使用cocos2d 2.0的iPhone5S上的旋转动画问题 [英] Rotation animation issue on iPhone5S with cocos2d 2.0

查看:251
本文介绍了使用cocos2d 2.0的iPhone5S上的旋转动画问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cocosbuilder2.1,cocos2d 2.0制作CCSprite旋转动画。它在iPhone4S(iOS 8.0.2),iPhone5模拟器,iPad 2模拟器,iPad视网膜模拟器,但在iPhone5S(iOS 7.1.1),iPhone5S模拟器,iPad空气模拟器,iPhone 6模拟器,iPhone上有抖动问题6 Plus模拟器。构建设置如下:



在目标下的构建设置中:



Base SDK =最新的iOS 8.0);
有效的架构= arm64 armv7 armv7s



一般在目标下:



部署目标= 6.0



一开始我认为这是cocosbuilder中的一个错误,但是通过手动使sprite旋转和有相同的问题测试后,我觉得cocos2d 2.0的兼容性有问题

 



code> - (void)onEnter {
[super onEnter];
... //播放音乐
... //加载图片资源
CCSprite * testSprite = [CCSprite spriteWithSpriteFrameName:@testIMG.png];
testSprite.position = ccp(200,200);
[self addChild:testSprite];
CCRotateBy * rotateAction = [CCRotateBy actionWithDuration:3 angle:360];
[testSprite runAction:rotateAction];
... //其他的东西,与CCBReader或cocosbuilder无关
}

抖动问题就像testSprite的旋转值已经设置为0 everyFrame ater它已被设置为正确的值。例如它就像它旋转到1,然后回到0,然后回到2,然后回到0,3,0,4,0 ...等等。所有这些发生得很快,这使得它闪烁。最后旋转总是重置为0.



我试过google它,但没有发现任何相关,因为这是一个非常个人的问题。

解决方案

如果是个人问题,请告诉我应该朝哪个方向找出错误的位置。虽然现在仍然确定是什么导致这个问题,我解决了它通过改变有效架构到armv7。这种构建设置不会利用新的架构在比iPhone4S更新的设备,但至少不会导致抖动问题。



====== ======更新=================



我发现与此问题相关的警告。 多个方法命名为setRotation'查看相关问题: ARC语义问题名为setRotation的多个方法而只归档



虽然我已经将cocos2d升级到v2.2版本(对于我的旧项目来说太复杂,但我还是得到了




$ b

最后,我使用类型转换在CCBAnimationManager.m中解决它。 code> @implementation CCBRotateTo
- (void)startWithTarget:(CCNode *)aTarget
{
[super startWithTarget:aTarget];
starAngle_ = [(CCNode *)self.target rotation];
diffAngle_ = dstAngle_ - startAngle_;
}

- (void)update:(ccTime)t
{
[(CCNode *)self.target setRotation:startAngle_ + diffAngle_ * t];
}

有了这个变化,现在我也可以支持arm64了。


I'm making a CCSprite rotating animation with cocosbuilder2.1, cocos2d 2.0. It works great on iPhone4S(iOS 8.0.2), iPhone5 Simulator, iPad 2 Simulator, iPad Retina Simulator, but has "jittering" problem on iPhone5S(iOS 7.1.1), iPhone5S Simulator, iPad Air Simulator, iPhone 6 Simulator, iPhone 6 Plus Simulator. The build setting is as follows:

In Build Settings under Targets:

Base SDK = Latest iOS (iOS 8.0); Valid Architectures = arm64 armv7 armv7s

In General under Targets:

Deployment Target = 6.0

At first I thought it's a bug in cocosbuilder, but after testing by manually making a sprite rotating and having the same problem, I feel there's something wrong in cocos2d 2.0's compatibility with iPhone5S.

code: in the layer of the first scene

-(void)onEnter {
    [super onEnter];
    ...//play music
    ...//load image resources
    CCSprite *testSprite = [CCSprite spriteWithSpriteFrameName:@"testIMG.png"];
    testSprite.position = ccp(200,200);
    [self addChild:testSprite];
    CCRotateBy *rotateAction = [CCRotateBy actionWithDuration:3 angle:360];
    [testSprite runAction:rotateAction];
    ...//other stuff, nothing related with CCBReader or cocosbuilder
}

The "jittering" problem is as if the rotation value of the testSprite has been set to 0 everyFrame ater it's been set to the right value. e.g. It's like it rotates to 1, then back to 0, then to 2, then back to 0, 3, 0, 4, 0 ... etc. And all these happens very quickly, which makes it kind of "blinking". At last the rotation is always reset to 0.

I tried google it, but found nothing related, as if this is a very personal problem. If it's a personal issue, please let me know which direction I should working towards to find where the bug is, thanks!

解决方案

Though still now sure what causes this problem, I solved it by changing the Valid Architectures to armv7. This build settings will not take advantages of new architectures on devices newer than iPhone4S, but at least won't cause the jittering issue.

==============Update=================

I found a warning that's related with this problem. "multiple methods named 'setRotation' " See related problem: ARC semantic issue "multiple methods named 'setRotation' " while archiving only

Though I've upgraded cocos2d to v2.2 version for my old project (too complex to update to v3), I still got the warning.

Finally I used type casting to solve it as following in CCBAnimationManager.m

@implementation CCBRotateTo
-(void)startWithTarget:(CCNode *)aTarget
{
    [super startWithTarget:aTarget];
    starAngle_ = [(CCNode *)self.target rotation];
    diffAngle_ = dstAngle_ - startAngle_;
}

-(void)update:(ccTime)t
{
    [(CCNode *)self.target setRotation: startAngle_ + diffAngle_ * t];
}

With this change, now I can support arm64 too.

这篇关于使用cocos2d 2.0的iPhone5S上的旋转动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆