gpt4 book ai didi

ios - Cocos2d : dealing with actions, 动画、 Action 序列和 CCTintBy

转载 作者:行者123 更新时间:2023-11-29 04:14:36 24 4
gpt4 key购买 nike

我曾经在运行新操作时stopAllActions。我注意到使用 CCTintBy 操作时存在一些问题,因为颜色是逐渐添加的,并且对“reverse”的调用(请参阅 CCTintBy 中的 (CCActionInterval*)verse 函数)没有被调用(停止)。

这让我想知道我目前对 CCActions 的方法和理解。

例如。我曾经在运行新 Action 时调用 [self stopAllActions] 但这并不适合 CCTintBy Action 的使用(它确实也会停止该 Action 并让 Sprite 变成半色,并且基色会发生相反的变化)函数不会因为被 stopAllActions 停止而被调用)。

我向您展示了我的项目中最常见的操作。我正在考虑不调用 stopAllActions,而是仅在操作尚未运行时调用停止特定操作。这是一个好的做法吗?

 -(void) runExplosionAnimation
{
[self stopAllActions];
//here should verify if the action is not already running and if so stop it
//To do so I should have a member variable like: CCAction * explosionAnim = [CCSequence actions: [CCAnimate actionWithDuration:0.4f animation:anim restoreOriginalFrame:false], [CCHide action], nil];
//Plus a boolean to distinguish if it is already running..

CCAnimation* anim = [[CCAnimationCache sharedAnimationCache] animationByName:@"bbb"];
if(anim!=nil){
[self runAction:[CCSequence actions: [CCAnimate actionWithDuration:0.4f animation:anim restoreOriginalFrame:false], [CCHide action], nil]];
}
else{
[self loadSharedAnimationIfNeeded];
}
}

使用 bool 值确定 CCTintBy 操作是否仍在运行的一种方法是在再次调用 CCTintBy 操作之前手动恢复原始颜色。

-(void) gotHitWithFactor:(int)factor
{
[self runGotHitAnimation];

self.hitPoints -= factor * 1;
if (self.hitPoints <= 0)
{
isAlive=false;
[self runExplosionAnimation]; //Will also set enemy visibility to false
}
}

-(void) runGotHitAnimation
{
//hitAction is initialized as [CCTintBy actionWithDuration:0.1f red:100 green:100 blue:111];

[self stopAction:hitAction];
self.color = originalColour; //Where originalcolour is initialized as self.colour
[self runAction:hitAction];
}

最佳答案

您知道可以标记操作,对吧?

CCNode 类具有以下方法:

stopActionByTag:
getActionByTag:

如果您运行新操作,您只需告知在每种特定情况下需要停止哪些其他操作。对于复杂的 Action 使用,我建议将您的 Action 逻辑上分为两组:游戏玩法和视觉效果。

游戏 Action 是影响游戏玩法的所有 Action ,例如移动。视觉就是视觉效果,比如倾斜、旋转、着色。这种区别的要点在于,它可以更轻松地确定操作的优先级。主要是,视觉 Action 不应该停止、奔跑或以其他方式影响游戏 Action 。

关于ios - Cocos2d : dealing with actions, 动画、 Action 序列和 CCTintBy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13902291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com