0

Hey i was wondering if there was a way to tell the name of the currently assigned frame to a specific sprite. What I want to do is have an if statement similar to

if(CGRectIntersectsRect([Player1 boundingBox], [Player2 boundingBox] && Player1.frame == Player2.frame){
    //Do something
}else if(CGRectIntersectsRect([Player1 boundingBox], [Player2 boundingBox] && Player1.frame != Player2.frame{
    //Do something else
}

Unfortunately i have no clue what the proper way to do this is. Can i get the actual name of the current sprite's frame. ie. @"Frame1.png" so i could compare it to the sprite it's colliding with's frame name? Also sorry if i'm using wrong terminology by frame i mean like the sprite's image from a sprite sheet ie. spriteWithSpriteFrameName.

2 Answers 2

0
CCSpriteFrame* frame = sprite.displayFrame;
NSString* frameName = frame.textureFilename;

I'm not sure if this returns individual frame names though. If it only returns the atlas texture filename you're out of luck. You'd have to modify the CCSpriteFrame code to include a frame name property.

0

Im not sure if it is a property on CCSprite, you would have to check the docs but a simple solution to this would be to use inheritance and subclass the CCSprite.

Add the properties you want, so the imageName property, change your CCSprite allocations to use the new subclassed sprite and you will then be able to access the property. Don't forget the imports.

Also, you should use CGRectEqualToRect ( CGRect rect1, CGRect rect2 ); to check for equality. Depending on your sprites, you might want correct collision detection to avoid transparency collision detection which the CGRect methods won't do.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.