朝一个方向移动 cocos2d-iphone+box2d 男孩
请有人就此给我建议。
我有一个 cocos2d-iphone +box2d 主体,我希望仅使用加速计控件和视差滚动在一个方向上移动(仅从 iphone 屏幕的左到右移动)。请问我该怎么做,因为一旦设备倾斜,身体就会向左和向右移动。我不想使用力量或冲动,因为我将不会启用触摸控制。 这是我的加速度计代码:
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration
*)acceleration {
float32 accelerationFraction = acceleration.y * 6;
if (accelerationFraction < -1) {
accelerationFraction = -1;
} else if (accelerationFraction > 1) {
accelerationFraction = 1;
b2Vec2 gravity(-acceleration.y *10, acceleration.x *10);
world->SetGravity( gravity );
}
提前感谢您的帮助。
Please can someone advice me on this.
I have a cocos2d-iphone +box2d body I wish to move only in one direction(movement only from left to right of the iphone screen) using only the accelerometer controls and parallax scrolling. Please how do I do this as at the moment the body moves both to the left and right once the device is tilted. I do not want to use forces or impulse since I will NOT be enabling touch controls.
This is my accelerometer code :
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration
*)acceleration {
float32 accelerationFraction = acceleration.y * 6;
if (accelerationFraction < -1) {
accelerationFraction = -1;
} else if (accelerationFraction > 1) {
accelerationFraction = 1;
b2Vec2 gravity(-acceleration.y *10, acceleration.x *10);
world->SetGravity( gravity );
}
Thanks in advance for your help .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 mouseJoints。看看这个 教程。在那里他准确地解释了你想要实现的目标。
You should use mouseJoints. Look at this tutorial. There he explains exactly what you are trying to accomplish.