Jump to content

need advice for 2d game


mladenst
 Share

Recommended Posts

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 collisions
    • finally 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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...