Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone Cocos2d 3.0重力花栗鼠:雪碧位置不';不变_Cocos2d Iphone_Chipmunk - Fatal编程技术网

Cocos2d iphone Cocos2d 3.0重力花栗鼠:雪碧位置不';不变

Cocos2d iphone Cocos2d 3.0重力花栗鼠:雪碧位置不';不变,cocos2d-iphone,chipmunk,Cocos2d Iphone,Chipmunk,将我的游戏从cocos2dv2移植到v3,我不知道精灵何时离开屏幕 在v2中,我的解决方案是: -(void) update:(ccTime) delta { // Should use a fixed size step based on the animation interval. int steps = 2; CGFloat dt = [[CCDirector sharedDirector] animationInterval]/(CGFloat)steps;

将我的游戏从cocos2dv2移植到v3,我不知道精灵何时离开屏幕

在v2中,我的解决方案是:

-(void) update:(ccTime) delta
{
   // Should use a fixed size step based on the animation interval.
   int steps = 2;
   CGFloat dt = [[CCDirector sharedDirector] animationInterval]/(CGFloat)steps;

   for(int i=0; i<steps; i++){
       cpSpaceStep(space_, dt);
   }

   if (mySprite.getPhysicsBody->p.y > 500)
       [mySprite resetPosition];
}
-(无效)更新:(ccTime)增量
{
//应根据动画间隔使用固定大小的步长。
int步数=2;
CGFloat dt=[[CCDirector sharedDirector]animationInterval]/(CGFloat)步骤;
对于(int i=0;ip.y>500)
[mySprite resetPosition];
}
现在使用cocos2dv3,mySprite.physicsNode.position不会随时间而改变

有什么想法或与一些例子有联系吗


谢谢。

physicsNode。位置不会随时间变化,因为它使用其父精灵坐标空间,而不是全局坐标空间

考虑到锚点,可以使用以下方法获得任何节点的全局位置:

CGPoint worldPos = [node convertToWorldSpaceAR:CGPointZero];
之后,如有必要,您可以使用以下工具轻松地将其转换为任何其他节点空间(如标高):

但是请注意,您不应该在代码上硬编码屏幕大小,因为每个设备的屏幕大小都不同。您可以改为使用:

CGSize viewSize = [[CCDirector sharedDirector] viewSize];
CGSize viewSize = [[CCDirector sharedDirector] viewSize];