cocos2d / cocos2d-objc

Cocos2d for iOS and OS X, built using Objective-C
http://www.cocos2d-objc.org
Other
4.07k stars 1.16k forks source link

3.1.0 - runAnimationsForSequenceNamed error when using Sprite Frame keyframes #829

Open tanis2000 opened 10 years ago

tanis2000 commented 10 years ago

I have a CCB file that has a CCNode and a child of the CCNode that is a CCSprite. I've set the spriteFrame of the CCSprite and made a new timeline that has some keyframes for the "Sprite Frame".

When I run the animation through the usual [self.animationManager runAnimationsForSequenceNamed:@"Hit"]; I get the following error:

-[Bullet setSpriteFrame:]: unrecognized selector sent to instance 0xc402a80

Bullet is the class of my CCNode. I don't understand why it's trying to set the Sprite Frame of the CCNode instead of the one of the CCSprite.

Here's the CCB file if needed: https://dl.dropboxusercontent.com/u/3098924/Bullet.ccb

tanis2000 commented 10 years ago

Sort of hacky solution: here's what I've done to get it working. But I'm not sure that's really needed or the correct way.

In my Bullet class I've added this property:

@property (nonatomic, strong) CCSprite *bulletSprite;

In SB I've set up as Owner var the value _bulletSprite.

And back in the code now I'm calling this:

[self.bulletSprite.animationManager runAnimationsForSequenceNamed:@"Hit"];
tanis2000 commented 10 years ago

I've been experimenting with this issue and my hacky solution isn't of much help as I'm not sure whether the animation will involve changing the frame of a sprite or not beforehand. So I suppose that the problem is in the CCBReader that doesn't set the correct object for which the frame should be changed.

Here's a stack trace that just happened:

2014-06-17 20:44:15.754 platformer[8870:60b] -[Bullet setSpriteFrame:]: unrecognized selector sent to instance 0x17471150
2014-06-17 20:44:15.807 platformer[8870:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Bullet setSpriteFrame:]: unrecognized selector sent to instance 0x17471150'
*** First throw call stack:
(
    0   CoreFoundation                      0x035ed1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x030ba8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0368a243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x035dd50b ___forwarding___ + 1019
    4   CoreFoundation                      0x035dd0ee _CF_forwarding_prep_0 + 14
    5   platformer                          0x000a4502 -[CCAnimationManager setAnimatedProperty:forNode:toValue:tweenDuration:] + 2050
    6   platformer                          0x000a4919 -[CCAnimationManager setKeyFrameForNode:sequenceProperty:tweenDuration:keyFrame:] + 873
    7   platformer                          0x000a6e17 -[CCAnimationManager runAnimationsForSequenceId:tweenDuration:] + 2215
    8   platformer                          0x000a71c5 -[CCAnimationManager runAnimationsForSequenceNamed:tweenDuration:] + 165
    9   platformer                          0x000a724d -[CCAnimationManager runAnimationsForSequenceNamed:] + 109
    10  platformer                          0x0002b626 -[Bullet hitWall] + 310
    11  platformer                          0x0002b8dc -[Bullet onCollisionEnter:collisionPair:] + 508
    12  platformer                          0x00037a58 -[World ccPhysicsCollisionBegin:default:default:] + 312
    13  platformer                          0x0013bcd0 PhysicsBegin + 448
    14  platformer                          0x00023ebf cpSpaceCollideShapes + 367
    15  platformer                          0x0005cc03 MarkLeaf + 371
    16  platformer                          0x0005c997 MarkSubtree + 55
    17  platformer                          0x0005c9b1 MarkSubtree + 81
    18  platformer                          0x0005c9b1 MarkSubtree + 81
    19  platformer                          0x0005c9c6 MarkSubtree + 102
    20  platformer                          0x0005c9c6 MarkSubtree + 102
    21  platformer                          0x0005bd25 cpBBTreeReindexQuery + 213
    22  platformer                          0x00024b67 cpSpatialIndexReindexQuery + 55
    23  platformer                          0x00024612 cpSpaceStep + 450
    24  platformer                          0x001b5811 -[ChipmunkSpace step:] + 65
    25  platformer                          0x0013ee62 -[CCPhysicsNode fixedUpdate:] + 1522
    26  platformer                          0x000cd65f InvokeMethods + 479
    27  platformer                          0x000cd3fd __19-[CCScheduler init]_block_invoke + 221
    28  platformer                          0x000ce0cb -[CCScheduler updateTo:] + 715
    29  platformer                          0x000cefc3 -[CCScheduler update:] + 195
    30  platformer                          0x00149c30 -[CCDirectorIOS drawScene] + 256
    31  platformer                          0x0014beac -[CCDirectorDisplayLink mainLoop:] + 92
    32  QuartzCore                          0x011f0d66 _ZN2CA7Display15DisplayLinkItem8dispatchEv + 48
    33  QuartzCore                          0x011f0c22 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 310
    34  QuartzCore                          0x011f1147 _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
    35  CoreFoundation                      0x035abac6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
    36  CoreFoundation                      0x035ab4ad __CFRunLoopDoTimer + 1181
    37  CoreFoundation                      0x03593538 __CFRunLoopRun + 1816
    38  CoreFoundation                      0x035929d3 CFRunLoopRunSpecific + 467
    39  CoreFoundation                      0x035927eb CFRunLoopRunInMode + 123
    40  GraphicsServices                    0x0530c5ee GSEventRunModal + 192
    41  GraphicsServices                    0x0530c42b GSEventRun + 104
    42  UIKit                               0x019f9f9b UIApplicationMain + 1225
    43  platformer                          0x0004cabc main + 92
    44  platformer                          0x00002a75 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException

The Bullet class this trace refers to is my main node for that CCB file, which is a CCNode with physics enabled. But the sequence (or timeline) changes the frame of a CCSprite that is a child of that CCNode.

tanis2000 commented 10 years ago

Here's the solution. My Bullet.ccb file had a piece of dictionary that shouldn't have been there. This is due to me changing the parent CCSprite to a CCNode by hand in the file (is there a way to do it directly in SB?).

When doing so, upon reopening the file in SB and saving it again, it doesn't purge the properties that are no longer pertinent to that kind of object. The result was that I still had this piece of XML lying around:

        <key>animatedProperties</key>
        <dict>
            <key>1</key>
            <dict>
                <key>spriteFrame</key>
                <dict>
                    <key>keyframes</key>
                    <array>
                        <dict>
                            <key>easing</key>
                            <dict>
                                <key>type</key>
                                <integer>0</integer>
                            </dict>
                            <key>name</key>
                            <string>spriteFrame</string>
                            <key>time</key>
                            <real>0.033333335071802139</real>
                            <key>type</key>
                            <integer>7</integer>
                            <key>value</key>
                            <array>
                                <string>Game/fireflash.png</string>
                                <string>Use regular file</string>
                            </array>
                        </dict>
                    </array>
                    <key>name</key>
                    <string>spriteFrame</string>
                    <key>type</key>
                    <integer>7</integer>
                </dict>
            </dict>
        </dict>