mladenst Posted September 20, 2014 Share Posted September 20, 2014 I'm new in the field of 2D game development and this is my first project http://codepen.io/mladen___/pen/fuFIH Can someone give me some advice? Or tell me if I'm doing something wrong. I'm trying to implement some JavaScript design pattern which I know from writing web-apps but it just does not work for me... Quote Link to comment Share on other sites More sharing options...
topheman Posted September 21, 2014 Share Posted September 21, 2014 Hello mladenst, As you're asking for advice/things you're doing wrong : 1) Cache Cache your assets (images in your case) -> only access the DOM once and store your images for good, don't access the DOM in each loops of each calls of yours draws. 2) Game loop You should use requestAnimationFrame() instead of setTimeOut() (better when you're making games, it's optimized to take advantage of hardward acceleration - handled by GPU). 3) Code organization (up to you) You should split the logic part (positions update of your entities + collisions checks) from the drawing part.In your gameLoop :first process positions and stuff (according to time and user input)then check for collisionsfinally draw If you know a little object oriented programming, you could do stuff like player.move(), player.checkCollision() ... This is all of the top of my head, I hope it will help you a little, there are lots of article about that kind of stuff (you could even use a game engine). Tophe mladenst 1 Quote Link to comment Share on other sites More sharing options...
mladenst Posted September 21, 2014 Author Share Posted September 21, 2014 Thank you very much topheman. I will try to implement all your advice. Is this the better version? http://codepen.io/mladen___/pen/fuFIH Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.