我想在 cocos2d 中创建一个游戏,其中一个对象正在运行。
我想根据设备加速度计左右移动这个对象。我正在获取加速度计的值并更新对象的位置。甚至我可以在 LOG 中看到新位置。但物体并没有从它的位置上移动。这是我在应用程序中编写的代码。
- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration1 { acceleration = acceleration1; CGPoint position = mainPlayer.position; if(acceleration.y < -0.25) { // tilting the device to the right position.y -= 0.25; } else if (acceleration.y > 0.25) { // tilting the device to the left position.y += 0.25; } else { } // newPosition = position; CCAction *action = [CCMoveTo actionWithDuration:0.01 position:position]; [mainPlayer runAction:action]; // mainPlayer.position = ccp(position.x, position.y); }
我通过直接设置位置和使用动作来尝试两种方式。
剂量任何人都知道为什么会发生此问题或加速度计工作需要任何设置。
请提供此类示例的任何链接。