我有这个代码来显示图像的动画
-(void) blink:(ccTime) delta {
animateblink ++; //adds 1 every frame
if (animateblink <= 6 ) { //if we included frames to show for breaking and the current frame is less than the max number of frames to play
if (animateblink < 6) {
[sprite setTexture:[[CCSprite spriteWithFile:[NSString stringWithFormat:@"%@_blinkk00%i.png", baseImageName,animateblink]] texture]];
[self unschedule:_cmd];
[self schedule:@selector(openEyes:) interval:0.1f];
[self schedule:@selector(moveSprite:) interval:0.1f];
}
}
}
我有 6 张类似动画的图片
dragonimage_blinkk001,dragonimage_blinkk002,dragonimage_blinkk003,dragonimage_blinkk004,dragonimage_blinkk005,dragonimage_blinkk006 like that
我放了两种方法,1:用于动画时间 2:用于图像的移动
代码是
-(void) openEyes:(ccTime) delta {
[sprite setTexture:[[CCSprite spriteWithFile:[NSString stringWithFormat:@"%@.png", baseImageName]] texture]];
[self unschedule:_cmd];
int blinkInterval = (arc4random() % 6) + 1; // range 3 to 8
[self schedule:@selector(blink:) interval:blinkInterval];
}
-(void)moveSprite:(ccTime)delta
{
movementCounter ++;
if (movementCounter == 1000) {
[self unschedule:_cmd];
}
else
{
spriteimagename.position = ccp(spriteimagename.position.x+10,spriteimagename.position.y);
}
}
但是第一种方法动画时间不正确,动画有很多延迟,我只想随机快速地显示图像的动画,它是龙飞动画。
我的第二个方法根本不起作用,我没有得到该图像的任何移动。
我希望你能理解我的问题。如何解决上述两个方法问题。提前致谢。