Cocos2d iphone 不断上下移动精灵COCOS2D3.0

Cocos2d iphone 不断上下移动精灵COCOS2D3.0,cocos2d-iphone,sprite,Cocos2d Iphone,Sprite,我试着不断地上下移动我的精灵 这是我的代码,但应用程序一直崩溃,当它到达这一点 // Add a sprite _player = [CCSprite spriteWithImageNamed:@"player.png"]; _player.position = ccp(self.contentSize.width/30,self.contentSize.height/2); _player.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){

我试着不断地上下移动我的精灵

这是我的代码,但应用程序一直崩溃,当它到达这一点

// Add a sprite
_player = [CCSprite spriteWithImageNamed:@"player.png"];
_player.position  = ccp(self.contentSize.width/30,self.contentSize.height/2);
_player.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, _player.contentSize} cornerRadius:0]; // 1
_player.physicsBody.collisionGroup = @"playerGroup"; //
CCActionProgressFromTo *upanddown = [CCActionProgressFromTo actionWithDuration:1.0 from:.8f to:.1f];
[_player runAction:[CCActionRepeatForever actionWithAction:upanddown]];
[_physicsWorld addChild:_player];

谢谢您的建议:D

如果您想上下移动它,请尝试以下操作之一:

[CCActionMoveBy actionWithDuration:1.0f position:ccp(moveX, moveY)];

“移动方式”会将其移动一个偏移量,而“移动到”会将其移动到特定位置。例如,要使用“按偏移量移动”将其上下移动,可以执行以下操作:

CCActionMoveBy* moveUp = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, 100.0f)];
CCActionMoveBy* moveDown = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, -100.0f)];
CCActionSequence* upAndDown = [CCActionSequence actions:moveUp, moveDown, nil];

[_player runAction:[CCActionRepeatForever actionWithAction:upAndDown]];

如果要上下移动,请尝试以下操作之一:

[CCActionMoveBy actionWithDuration:1.0f position:ccp(moveX, moveY)];

“移动方式”会将其移动一个偏移量,而“移动到”会将其移动到特定位置。例如,要使用“按偏移量移动”将其上下移动,可以执行以下操作:

CCActionMoveBy* moveUp = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, 100.0f)];
CCActionMoveBy* moveDown = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, -100.0f)];
CCActionSequence* upAndDown = [CCActionSequence actions:moveUp, moveDown, nil];

[_player runAction:[CCActionRepeatForever actionWithAction:upAndDown]];

如果要上下移动,请尝试以下操作之一:

[CCActionMoveBy actionWithDuration:1.0f position:ccp(moveX, moveY)];

“移动方式”会将其移动一个偏移量,而“移动到”会将其移动到特定位置。例如,要使用“按偏移量移动”将其上下移动,可以执行以下操作:

CCActionMoveBy* moveUp = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, 100.0f)];
CCActionMoveBy* moveDown = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, -100.0f)];
CCActionSequence* upAndDown = [CCActionSequence actions:moveUp, moveDown, nil];

[_player runAction:[CCActionRepeatForever actionWithAction:upAndDown]];

如果要上下移动,请尝试以下操作之一:

[CCActionMoveBy actionWithDuration:1.0f position:ccp(moveX, moveY)];

“移动方式”会将其移动一个偏移量,而“移动到”会将其移动到特定位置。例如,要使用“按偏移量移动”将其上下移动,可以执行以下操作:

CCActionMoveBy* moveUp = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, 100.0f)];
CCActionMoveBy* moveDown = [CCActionMoveBy actionWithDuration:1.0f position:ccp(0.0f, -100.0f)];
CCActionSequence* upAndDown = [CCActionSequence actions:moveUp, moveDown, nil];

[_player runAction:[CCActionRepeatForever actionWithAction:upAndDown]];