开发者

Sprite under map

开发者 https://www.devze.com 2023-03-01 20:22 出处:网络
Hello i have some sprite and some map -(id) init { if( (self=[super init] )) { self.tiledMap = [CCTMXTiledMap tiledMapWithTMXFile:@\"map3.tmx\"];

Hello i have some sprite and some map

-(id) init {

if( (self=[super init] )) {

    self.tiledMap = [CCTMXTiledMap tiledMapWithTMXFile:@"map3.tmx"];
    self.background = [_map layerNamed:@"Background"];
    [self.tiledMap runAction:[CCMoveBy actionWithDuration:10.0 position:ccp(0,-2750)]];


    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"AnimBear.plist"];
    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"AnimBear.png"];
    [self addChild:spriteSheet];
    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for (int i = 1; i <= 8 ; ++i) {
        [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"bear%d.png", i]]];
    }
    CCAnimation *walkAnim = [CCAnimation animationWith开发者_StackOverflow社区Frames:walkAnimFrames delay:0.1f];

    CGSize winSize = [CCDirector sharedDirector].winSize;
    self.bug = [CCSprite spriteWithSpriteFrameName:@"bear1.png"];
    _bug.position = ccp(winSize.width/2, winSize.height/2);
    self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];




    [_bug runAction:_walkAction];
    [spriteSheet addChild:_bug];
    [self addChild:_map];
}
return self;

}

and my sprite is under map , but i need to draw sprite on map. How can i do it? tnaks


the problem is that ure missing the z value, that tells the order of the stuff,

[spriteSheet addChild:_bug z:2];
[self addChild:_map z:1];

The layer organizes the objects that are infront of or behind using zOrder the lowest the value, the far is the thing from the screen.

0

精彩评论

暂无评论...
验证码 换一张
取 消