Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

198 Neutral

About Fl00Fy

  • Rank
  1. Fl00Fy

    Serving html file for webgame.

    I managed to get it working using express.static middleware to serve all the scripts and resources, by adding the following lines: app.use('/Scripts', express.static(__dirname + '/Scripts')); app.use('/Images', express.static(__dirname + '/Images')); app.use('/Sounds', express.static(__dirname + '/Sounds')); I tried using a '/public' folder to do this but I couldn't get it working. I'll probably play around with it to find out why as I think it would be cleaner.  Thanks for your help!
  2. Fl00Fy

    Serving html file for webgame.

    I tried removing the '../' but unfortunately I'm still getting the same error: "Failed to load resource: the server responded with a status of 404 (not found)". I was under the impression that it would look for the scripts from where the html file that is trying to link them is. In this case the html file is in Views, and would need to go up one level in order to get into Scripts. Or does it look from the root directory regardless of which file is searching?
  3. Hello   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"> <head> <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; } </style> </head> <body> <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 game.state.start('Boot'); })(); </script> </body> </html> 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.    Thanks!
  4. That was indeed the problem I was having. I remember actually changing a 3 to a 2 before for the UV coords thinking "there's only 2 components in a texture coordinate"!  Thanks so much for the help!
  5. Hey   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:  [attachment=26339:Screenshot 1.png]   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 indices.push_back(face.mIndices[index]); } } returnMesh.numOfIndices[meshIndex] = indices.size(); glBindVertexArray(returnMesh.vaos[meshIndex]); 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); glEnableVertexAttribArray(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); glEnableVertexAttribArray(1); } // 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); glEnableVertexAttribArray(2); } if (indices.size() > 0) { glGenBuffers(1, &VBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), indices.data(), GL_STATIC_DRAW); } // unbind vertex array glBindVertexArray(0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } return returnMesh; } How I'm loading the textures: GLuint 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, &widthAsInt, &heightAsInt, &componentsInImageFile, req_comp); 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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); if ((req_comp == 2) || (req_comp == 4)) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthAsInt, heightAsInt, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, widthAsInt, heightAsInt, 0, GL_RGB, GL_UNSIGNED_BYTE, image); } glBindTexture(GL_TEXTURE_2D, 0); stbi_image_free(image); } else { 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. 
  6. Alright thanks. That simplifies it a lot for me. 
  7. 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; //Constructors... public GameObject drawCard() { if (cards.Count == 0) { //Merge discard pile with deck } GameObject temp = cards[iterator]; cards.RemoveAt(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); cards.Add(card); numCards++; } } 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. 
  8. I created another project and it worked perfectly fine, and also helped me realise where I made a mistake, and a very stupid mistake it was. In my GLSurfaceView implementation, I still had overridden, empty stubs for its onSurfaceCreated() and onSurfaceChanged() methods.    Thank you for the help Angex.
  9. No runtime errors at all.  I've tested it on two devices, both of which are supposedly 2.0 compatible, but I tried switching it to 1.0 anyway and it didn't make any difference.  I haven't implemented any threads, no. I was under the impression OpenGL ES isn't compatible with threads?   I can't think of what else might be causing this. I am also currently using the Kindle Development Kit, as one of my devices is the Kindle Fire. I don't know if maybe there's something about that kit which I don't know? I haven't found anything concerning OpenGL problems on the Kindle though.   I'll create another project today and setup and test OpenGL again, and see if I can get that working.  
  10. 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 { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature (Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(new MainView(this)); } @Override 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) { super(context); setEGLContextClientVersion(2); renderer = new GLRenderer (context, this); setRenderer (renderer); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); } } 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); } @Override public void onDrawFrame(GL10 gl) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); game.draw(); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl20.onSurfaceChanged(width, height); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl20.onSurfaceCreated(); game = new MainGame (view, gl20); game.setRunning(true); game.start(); } public void onSurfaceDestroyed () { game.setRunning(false); } public void onTouchEvent (MotionEvent event) { game.handleTouchEvent(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. 
  11. Thanks for all the advice. I'll probably end up adding the vector implementation. It's about time I start using them to be honest. And the article was a great help, thanks. 
  12. 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. 
  13. Ah ok. std:vector of objects it is. Thanks again for all the help. 
  14. Thanks. I'll definitely look into it.  Would it be best used as a vector containing unique_ptrs to Objects, as in  std::vector<std::unique_ptr<Object>> AllObjects;     ... possibly..... or as a dynamically-allocated array of Objects, like std::unique_ptr<Object[]>... possibly.    Would I be correct in assuming the first one is better? Since it would handle individual objects that need deleted better. 
  15. Alright. That's great. Thank you. You've been a great help. 
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!