Box2dweb,移动画布?
我目前正在使用 html5/js 开发一款游戏,使用 box2dweb 进行碰撞,但我遇到了需要与玩家一起滚动关卡的问题。 Box2d 直接渲染到 2d 上下文,所以我认为在当前状态下没有办法移动画布的渲染部分?
在 as3 中,您可以将所有内容放入影片剪辑中并相应地更改其位置。
那么,是否有可能以某种方式控制某种相机或画布对象的渲染部分来移动其“位置”以始终保持玩家居中?
预先感谢,
M0rph3v5
I'm currently working on a game with html5/js, using box2dweb for the collision but I'm running into the issue where I am required to scroll the level with the player. Box2d renders directly to the 2d context so I think in it's current state there is no way to shift the render portion of the canvas?
In as3 you could just put everything in a movieclip and change it's position accordingly.
So, is it possible in anyway to have control of a camera of some sorts or the render portion of the canvas object to shift it's 'position' to keep the player centered at all times?
Thanks in advance,
M0rph3v5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Box2D 本身不绘制任何东西,它只是计算位置/碰撞。
它提供了所谓的“调试绘图”,但它的目的是......调试。
无论如何,您可以从那里开始添加所有需要的功能。
http://code.google.com/p/box2d/wiki/FAQ
Box2D, by itself, doesn't draw anything, it just calculates positions/collisions.
It offers the so-called "Debug Drawing", but it's purpose is... debug.
Anyway you could start from there to add all the needed features.
http://code.google.com/p/box2d/wiki/FAQ
是的,我想,事实证明我必须在 debugdraw 之前使用 context.translate 来“移动”所有内容。现在工作得很好了。
编辑:
我当前使用的代码
,其中 xpos 和 ypos 是汽车的 x 和 y 位置,之后我只是在 0,0 处绘制实际的汽车精灵(以汽车尺寸除为中心)。
Yeah I figured, turns out I had to use a context.translate right before the debugdraw as well to 'shift' everything. Got it working nicely now.
EDIT:
The code I'm currently using
where xpos and ypos are the x and y positions of the car, after that i just draw the actual car sprite at 0,0 (with the carsize divided as the center).