I'm a total noob and im trying to integrate a spritesheet but the cocos2d tutorials and programming guide are outdated.
also, I have the newest bleeding edge version of cocos2d and xcode 4.1.
spritesheet in bleeding edge
(8 posts) (5 voices)-
Posted 9 months ago #
-
If you download cocos2d there's a cocos2d for iphone project in the downloaded zip. Start it. There are some spritesheet tests.
Posted 9 months ago # -
ok ill try it
Posted 9 months ago # -
adapting the cocos2d sample code didn"t work, this is the code i used
in my init method:
CGSize s = [[CCDirector sharedDirector] winSize]; [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"animations/ninja.plist"]; int idx = CCRANDOM_0_1() * 1400 / 100; int x = (idx%5) * 85; int y = (idx/5) * 121; CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"animations/ninja.png"]; [self addChild:spriteSheet z:0]; player = [CCSprite spriteWithTexture:spriteSheet.texture rect:CGRectMake(x,y,85,121)]; [player setPosition:ccp( s.height-57+21.5, 45 )]; [spriteSheet addChild:player];errors: on NSAssert(texture!=nil, @"Invalid texture for sprite"); thread1 program received sigabrt
*****UPDATED*****
Posted 9 months ago # -
But what didn't work? What are your errors?
Posted 9 months ago # -
You don't need to specify a folder, try converting @"animations/ninja.plist" to @"ninja.plist" and the same for your batchnode
Posted 9 months ago # -
[CCSprite spriteWithTexture:spriteSheet.texture rect:CGRectMake(x,y,85,121)];Too much work!
If you've made your plist, why waste time specifiying the rects.
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"nameOfYourImageInTheSpritesheet.png"]; [spritesheet addChild:sprite];Posted 9 months ago # -
Thank you all for your responses.
Posted 9 months ago #
Reply
You must log in to post.