Hi there! First I would like to thank everyone, you already helped me a lot with all the posts about isometric tiles and z ordering.
I have 2 questions that I still didn't found an answer:
In my tests I've subclassed a CCLayer and in this subclass I've included an CCSpriteSheet using this in implementation (just posted the important part)
@implementation characterLayer
- (id) init
{
self = [super init];
if (self != nil)
{
//CGSize winSize = [[CCDirector sharedDirector] winSize];
// Create a SpriteSheet -- just a big image which is prepared to
// be carved up into smaller images as needed
CCSpriteSheet *BastSheet = [CCSpriteSheet spriteSheetWithFile:@"BastRotation.pvr" capacity:20];
// Add sprite sheet to parent (it won't draw anything itself, but
// needs to be there so that it's in the rendering pipeline)
[self addChild:BastSheet];
// Load sprite frames, which are just a bunch of named rectangle
// definitions that go along with the image in a sprite sheet
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"BastRotation.plist"];
// Finally, create a sprite, using the name of a frame in our frame cache.
BastSprite = [CCSprite spriteWithSpriteFrameName:@"defend_0.png"];
//BastSprite.position = ccp(winSize.width/2, winSize.height/2);
// Add the sprite as a child of the sheet, so that it knows where to get its image data.
[BastSheet addChild:BastSprite];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 0; i <= 7; ++i)
{
[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"defend_%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithName:@"walk" delay:0.1f frames:walkAnimFrames];
CCAction *walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[BastSprite runAction:walkAction];
}
return self;
}
-(void)dealloc
{
//[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[super dealloc];
}
@end
after that, in the main gameScene I'm working on, I'm instantiating the new class I've created.
Everything is working fine, I'm being able to use
characterLayer *bastChar = [characterLayer node];
bastChar.position = ccp(0,-100);
[self addChild:bastChar];
[bastChar setVertexZ: (-bastChar.position.y + 80)/32];
Even the Z depth is working, but I would like to ask:
1 - The fact that I'm using the SpriteSheet inside an "CCLayer" subclass, and then instancing this CCLayer subclass is going to break down the performance of one draw call, or I still get this benefit?
2 - using " CCSpriteSheet *BastSheet = [CCSpriteSheet spriteSheetWithFile:@"BastRotation.pvr" capacity:20]; " inside the subclass is going to generate one spriteSheet for each instance of this subclass I create, or all of them are going to reuse the same one?
Thanks a lot for all the help!
I really looked in many topics, but still wasn't abe to get those 2 questions answered.