简体   繁体   English

设置在coco2d iPhone应用程序中移动的b2Body类对象的限制

[英]Set limit for b2Body class object moving in coco2d iPhone application

I have one object of b2Body class. 我有一个b2Body类的对象。 But I was it to move just say 25% of the screen from bottom. 但是我只是说要从底部移动屏幕的25%。 But it keeps moving though i set boundries. 但是,尽管我设定了界限,但它仍在继续前进。

Another option was to use setPosition once i reach that condition but in documentation this method exists but while implementation it throws error. 另一种选择是在达到该条件后使用setPosition,但在文档中此方法存在,但在实现时会引发错误。

Can anyone please help? 谁能帮忙吗?

Thank you, 谢谢,

Ankita 安基塔

Here's a great tutorial that explains the basics of box2D demonstrated using cocos2d for drawing. 这是一个很棒的教程,解释了使用cocos2d进行绘图演示的box2D基础。 It specifically shows how to make physical boundaries for the screen, which i think is a better way of achieving what you want to do than "interfering" with the box2d world by setting positions and forces directly. 它专门显示了如何为屏幕设置物理边界,我认为这是比直接设置位置和力“干扰” box2d世界更好的方法。

You can just add CCColorLayer and put b2Body into it. 您可以只添加CCColorLayer并将b2Body放入其中。 It will move for that layer only. 它将仅针对该层移动。 You can give x,y, heigh and width for layer. 您可以指定x,y,高度和宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM