Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 15 Mar 2013
Offline Last Active Apr 12 2015 01:50 PM

Topics I've Started

Serving html file for webgame.

28 March 2015 - 02:18 PM



I've just started learning JavaScript and trying to create a multiplayer webgame using Node.js. I decided to use Amazon's web services to store the website and run the servers, but I can't figure out what exactly to do in order to load the website when a user goes to the url. I'm using Amazon's Elastic Beanstalk service to host the game, which includes storage for my html and js files, and compute servers for running a server when there are players. As far as I have been able to find out, when I connect to the site, one of my js files are run (either app.js or server.js). In order to load the website I need to send the user the html. 

Unfortunately, I can't manage to properly send the html file without errors, because the html file links some scripts which are then not found because they haven't been sent. 

I've never worked with servers before so I won't be surprised if the answer is embarrassingly obvious. There are 3 different areas in which I could use the help right now:

  • Properly serving an html file to a user along with the necessary scripts
  • Properly using Amazon's Elastic Beanstalk for hosting a website/webgame
  • More appropriate suggestions for hosting than Elastic Beanstalk

Currently this is how I am trying to send the html file to the user (called index.js)

var express = require('express');
var app = express();

app.get('/', function(req, res){
    res.sendFile(__dirname + '/Views/index.html');

var server = app.listen(3000, function () {

    var host = server.address().address;
    var port = server.address().port;

    console.log('Example app listening at http://%s:%s', host, port);

And this is the html file containing the website and the entry point of the game

<html lang="en">
    <meta charset="UTF-8" />
    <title>Phaser - Tutorial</title>
    <script type="text/javascript" src="../Scripts/phaser.min.js"></script>
    <script type="text/javascript" src="../Scripts/States/Boot.js"></script>
    <script type="text/javascript" src="../Scripts/States/Preloader.js"></script>
    <script type="text/javascript" src="../Scripts/States/MainMenu.js"></script>
    <script type="text/javascript" src="../Scripts/States/Game.js"></script>
    <script type="text/javascript" src="../Scripts/States/Options.js"></script>
    <script type="text/javascript" src="../Scripts/States/HighScore.js"></script>
    <script type="text/javascript" src="../Scripts/States/Login.js"></script>
    <script type="text/javascript" src="../Scripts/States/LoginSuccessful.js"></script>
    <script type="text/javascript" src="../Scripts/States/LoginUnsuccessful.js"></script>
    <script type="text/javascript" src="../Scripts/States/LevelComplete.js"></script>
    <script type="text/javascript" src="../Scripts/States/GameOver.js"></script>
    <style type="text/css">
        body {
            margin: 0;
<script type="text/javascript">

    (function() {
        // initialize the framework
        var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game');
        // add game states
        game.state.add('Boot', Demo.Boot);
        game.state.add('Preloader', Demo.Preloader);
        game.state.add('MainMenu', Demo.MainMenu);
        game.state.add('Game', Demo.Game);
        game.state.add('Options', Demo.Options);
        game.state.add('HighScore', Demo.HighScore);
        game.state.add('Login', Demo.Login);
        game.state.add('LoginSuccessful', Demo.LoginSuccessful);
        game.state.add('LoginUnsuccessful', Demo.LoginUnsuccessful);
        game.state.add('LevelComplete', Demo.LevelComplete);
        game.state.add('GameOver', Demo.GameOver);
        // start the Boot state



And currently my project file structure is as follows:

  • root
    • index.js
    • Views
      • index.html
    • Scripts
      • States
        • ...
      • phaser.min.js


Any help on any at all would be greatly appreciated. 



Texture Mapping problems with Assimp

09 March 2015 - 11:05 AM



I've run into a problem trying to apply textures to a model which is loaded in through the Assimp model loader. The model is a simple 8 vertex cube. I've checked inside both Blender and 3DS Max to see if the UV mapping is correct, and it does seem to be. The texture is black and white checkers, and is 256x256 (in case the problem was the texture needed padding). 

I've exported the model in several different formats, and I've tried several different textures. The strange thing is that some of the model formats have different problems regarding the texture. In all cases it seems to be something to do with the UV coordinates, and since Blender and 3DS Max seem to believe they're correct, I'm under the impression that perhaps I'm loading the UV coordinates incorrectly. I'm also quite sure that the images are loaded correctly, as the images for the skybox are working fine, the difference being that the skybox generates it's own UV coordinates to use. 


Here's a screenshot of the scene: 

Attached File  Screenshot 1.png   393.92KB   0 downloads


How I'm loading the models:

static Mesh
	loadMesh(char *filename)
		Mesh returnMesh;
		Assimp::Importer *importer = new Assimp::Importer();
		const aiScene *scene = importer->ReadFile(filename, 
			aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_GenUVCoords | aiProcess_TransformUVCoords);

		returnMesh.numMeshes = scene->mNumMeshes;
		returnMesh.numOfIndices = new GLuint[returnMesh.numMeshes];
		returnMesh.vaos = new GLuint[returnMesh.numMeshes];
		// generate and set up a VAO for each mesh
		glGenVertexArrays(returnMesh.numMeshes, returnMesh.vaos);

		for (unsigned int meshIndex = 0; meshIndex < scene->mNumMeshes; meshIndex++)
			std::vector<GLuint> indices;
			const aiMesh* currentMesh = scene->mMeshes[meshIndex];

			for (unsigned int faceIndex = 0; faceIndex < currentMesh->mNumFaces; faceIndex++)
				aiFace face = currentMesh->mFaces[faceIndex];

				assert(face.mNumIndices == 3);

				for (int index = 0; index < 3; index++)
					//Add indices

			returnMesh.numOfIndices[meshIndex] = indices.size();


			GLuint VBO;

			if (currentMesh->HasPositions())
				glGenBuffers(1, &VBO);
				glBindBuffer(GL_ARRAY_BUFFER, VBO);
				glBufferData(GL_ARRAY_BUFFER, currentMesh->mNumVertices * 3 * sizeof(GLfloat), currentMesh->mVertices, GL_STATIC_DRAW);
				glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

			// VBO for normal data
			if (currentMesh->HasNormals()) {
				glGenBuffers(1, &VBO);
				glBindBuffer(GL_ARRAY_BUFFER, VBO);
				glBufferData(GL_ARRAY_BUFFER, currentMesh->mNumVertices * 3 * sizeof(GLfloat), currentMesh->mNormals, GL_STATIC_DRAW);
				glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);

			// VBO for tex-coord data
			if (!building && currentMesh->HasTextureCoords(0)) {
				glGenBuffers(1, &VBO);
				glBindBuffer(GL_ARRAY_BUFFER, VBO);
				glBufferData(GL_ARRAY_BUFFER, currentMesh->mNumVertices * 2 * sizeof(GLfloat), currentMesh->mTextureCoords[0], GL_STATIC_DRAW);
				glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
			if (indices.size() > 0) {
				glGenBuffers(1, &VBO);
				glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), indices.data(), GL_STATIC_DRAW);

			// unbind vertex array
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);


		return returnMesh;

How I'm loading the textures:

    loadImage(char *fileName, int req_comp, uint32_t &width, uint32_t &height)
        GLuint result;

        int widthAsInt;
		int heightAsInt;
        int componentsInImageFile;
        unsigned char* image = NULL;
        image = stbi_load(fileName,

		width = widthAsInt;
		height = heightAsInt;

        if (image != NULL)
            glGenTextures(1, &result);

            glBindTexture(GL_TEXTURE_2D, result);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

			if ((req_comp == 2) || (req_comp == 4))
							 widthAsInt, heightAsInt,
							 widthAsInt, heightAsInt,

            glBindTexture(GL_TEXTURE_2D, 0);

            std::cout << "Failed to Load Image: " << fileName << std::endl;

        return result;

Had this problem for a couple weeks now and running out of ideas of how to fix it. 

Reference/Value types in C#

10 November 2013 - 08:29 AM

I'm busy trying to make a game in Unity3D, but haven't had much experience in C# and having some trouble finding any specifics on how value/reference types are handled. I understand the basics of it; that most primitive data types, structs and enums are value type (unless specified by the ref qualifier), and all classes are reference types. Knowing that, I'm assuming the code I've currently got isn't working the way I meant it to because of my lack of knowledge. I'm trying to make a fairly simple card game, and have a Hand class, and a Deck class, both of which are simply containers for Card objects.

public class Deck
	private List<GameObject> cards;
	private const int TOTAL_CARDS = 52;
	private int iterator;


	public GameObject drawCard()
		if (cards.Count == 0)
			//Merge discard pile with deck
		GameObject temp = cards[iterator];
		return temp;
public class Hand{
	private List<GameObject> cards;
	private int numCards;
	private Deck deck;
	public Hand(Deck deck)
		this.deck = deck;
		numCards = 0;
		cards = new List<GameObject>(15);

	public void drawCard()
		GameObject card = deck.drawCard();
		Transform cardTransform = card.transform;
		cardTransform.position.Set(1, 1, 1);
		cardTransform.Rotate(new Vector3(0, 1, 0), 180);

Above is a simplified version of those two classes, the methods the question pertains to is the drawCard() methods in both classes. In the Deck's drawCard method, would removing the object from the List remove a reference or an object; and would the object returned by that method and used in the Hand's drawCard method be a reference pointing to an object that has been deleted(removed from the list) or will it be retained?


Thanks for any help. 

Problem setting up GLSurfaceView.Renderer

09 September 2013 - 06:46 AM

I'm trying to create an android app using OpenGL ES, but having some trouble with the GLSurfaceView.Renderer. 

Here's some of my code:

public class MainActivity extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature (Window.FEATURE_NO_TITLE);
		setContentView(new MainView(this));

	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;

public class MainView extends GLSurfaceView {

	private GLRenderer renderer;
	public MainView(Context context) {
		renderer = new GLRenderer (context, this);
		setRenderer (renderer);
public class GLRenderer implements Renderer {

	private MainView view;
	private MainGame game; //This is where the game logic begins.
	private GLRes gl20; //This is a class to initialise and store resources such as matrices and shaders
	public GLRenderer (Context context, MainView view)
		this.view = view;
		gl20 = new GLRes (context);
	public void onDrawFrame(GL10 gl) {

	public void onSurfaceChanged(GL10 gl, int width, int height) 
		gl20.onSurfaceChanged(width, height);

	public void onSurfaceCreated(GL10 gl, EGLConfig config) 

		game = new MainGame (view, gl20);
	public void onSurfaceDestroyed ()
	public void onTouchEvent (MotionEvent event)

The constructor of the Renderer is called as expected, but its onSurfaceCreated() is not, and therefore none of the other methods either, including onDrawFrame(). My GLSurfaceView's onSurfaceCreated is, however, called. This leads to me assume that I haven't set something up properly somewhere, regarding OpenGL and the Renderer, but I can't think what or where that could be. 

Gravity's affect on velocity implemented with speed and direction.

19 April 2013 - 12:37 PM

Sorry if the title's a bit confusing, had trouble trying to summarise the problem in a good way. 

Anywho, it seems I may have coded myself into a bit of pickle. I'm trying to create a game which includes gravity and some stuff which is affected by it... I decided, when I started the project, that I would describe each objects velocity with two scalars: speed and direction (in radians, right being 0). It's worked out well so far, until I tried to implement gravity.


The problem is, I can't figure out how to account for gravity by giving the object a downward force. If this just happens to be a bad way to implement velocity, I would be alright with having to change the code to use a different method; but if there is a viable solution for this, I'd love to hear it. 


Help of any kind would be appreciated.