我需要帮助
我正在开发一个简单的 2d 游戏,其中角色左右行走。
我正在使用我应用 CCAnimation 的 6 帧的sneakyjoystick 和步行动画
我遇到的问题是,当我从操纵杆更新方法调用动画时,动画仅在我从左操纵杆释放左或右按钮时开始......在我看来,我错过了一些简单的东西,但我无法弄清楚...
-(void) update:(ccTime)deltaTime
{
CGPoint scaleVelocity = ccpMult(leftJoystick.velocity, 100);
CGPoint oldPosition = [self.Bartender position];
CGPoint newPosition = ccp(self.Bartender.position.x + scaleVelocity.x * deltaTime, self.Bartender.position.y + scaleVelocity.y * deltaTime);
[self.Bartender setPosition:newPosition];
if (oldPosition.x > newPosition.x) {
[self.Bartender stopAllActions];
self.Bartender.flipX = YES;
[self GoWalk];
} else if (oldPosition.x == newPosition.x) {
// Intentionally do nothing to preserve orientation at start of scene!
NSLog(@"equal");
} else {
[self.Bartender stopAllActions];
self.Bartender.flipX = NO;
[self GoWalk];
}
/*
if(oldPosition.x > newPosition.x)
{
aChar.flipX = YES;
}
else if(aChar.flipX == YES)
{
aChar.flipX = NO;
}
if(jumpButton.active == YES)
{
CCLOG(@"jump pressed");
}
if(attackButton.active == YES)
{
CCLOG(@"attack pressed");
}
[aChar setPosition:newPosition];*/
}
-(void)GoStand
{
self.StandAnimation = [CCAnimation animation];
[self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];
[self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];
[self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk4.png"]];
[self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];
[self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];
id animatedAction = [CCAnimate actionWithDuration:0.8f animation:self.StandAnimation restoreOriginalFrame:NO];
id repeatAction = [CCRepeatForever actionWithAction:animatedAction];
[self.Bartender runAction:repeatAction];
}
-(void)GoWalk
{
self.WalkAnimation = [CCAnimation animation];
[self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk1.png"]];
[self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk2.png"]];
[self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk3.png"]];
[self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk4.png"]];
[self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk5.png"]];
[self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk6.png"]];
id animatedAction = [CCAnimate actionWithDuration:0.8f animation:self.WalkAnimation restoreOriginalFrame:NO];
id repeatAction = [CCRepeatForever actionWithAction:animatedAction];
[self.Bartender runAction:repeatAction];
}
有人吗?