Box2dWeb positioning relative to HTML5 Canvas

Posted by Joe on Game Development See other posts from Game Development or by Joe
Published on 2012-10-15T15:23:28Z Indexed on 2012/10/15 15:54 UTC
Read the original article Hit count: 257

Filed under:
|
|
|
|

I'm new with HTML5 canvas and Box2DWeb and I'm trying to make an Asteroids game. So far I think I'm doing okay, but one thing I'm struggling to comprehend is how positioning works in relation to the canvas. I understand that Box2DWeb is only made to deal with physical simulation, but I don't know how to deal with positioning on the canvas. The canvas is 100% viewport and thus can vary size. I want to fill the screen with some asteroids, but if I hardcore certain values such as bodyDef.position.x = Math.random() * 50; the asteroid may appear off canvas for someone with a smaller screen? Can anybody help me understand how I can deal with relative positioning on the canvas?

© Game Development or respective owner

Related posts about game-design

Related posts about box2d