how to pause and resume action applied to the ccSprite?(如何暂停和恢复应用于 ccSprite 的操作?)
问题描述
我创建了一个类似
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"Actor.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"Actor.pvr.ccz"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"clip000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.07f];
playWalkSound = [CCCallFuncN actionWithTarget:self selector:@selector(PlayRunningSound:)];
walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[actor runAction:[CCSpawn actions:walkAction, nil]];
我想在特定帧和特定触发器上暂停此动画.然后在特定触发后再次恢复动画.
I want to pause this animation on particular frame and particular trigger. and then again resume animation after particular trigger.
我尝试使用 stopAction,然后再次使用 runAction.但它在一些迭代后停止工作.我需要再次制作动画和动作才能再次运行该动画.
I tried using stopAction and then again runAction. But it stops working after some iteration. and i need to crate animation and action again in order to run that animation again.
我尝试使用 pauseSchedulerAndAction 和 resumeSchedulerandAction 但随后游戏暂停,如果我尝试再次触发暂停而不恢复游戏崩溃.
I tried using pauseSchedulerAndAction and resumeSchedulerandAction but then game get paused and if i try to trigger pause again without resuming game crashes.
是否有任何东西会暂停特定帧上的动画并从同一帧再次恢复.
is there anything that will pause the animation on particular frame and resum again from same frame.
推荐答案
我通过创建 1 帧动画解决了我的问题
I solved my problem by creating a animation with 1 frame
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"Actor.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"Actor.pvr.ccz"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <2; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"clip000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.07f];
playWalkSound = [CCCallFuncN actionWithTarget:self selector:@selector(PlayRunningSound:)];
walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[actor runAction:[CCSpawn actions:walkAction, nil]];
我使用上面的代码来暂停我的动画动作.并在我想恢复动画动作时添加以下代码.
i used the above code where i want to pause my animation action. and added following code when i want to resume the animation action.
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"Actor.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"Actor.pvr.ccz"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"clip000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.07f];
playWalkSound = [CCCallFuncN actionWithTarget:self selector:@selector(PlayRunningSound:)];
walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[actor runAction:[CCSpawn actions:walkAction, nil]];
这篇关于如何暂停和恢复应用于 ccSprite 的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何暂停和恢复应用于 ccSprite 的操作?
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01