0

我的初始化中有这段代码:

-(id)init {
    if ((self = [super init])) {
        CGSize screenSize = [CCDirector sharedDirector].winSize;
        mapSize = CGSizeMake(4000, 4000);

        rotateWorld = [CCNode node];
        [rotateWorld setContentSize:mapSize];
        rotateWorld.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);

        positionWorld = [CCNode node];
        [positionWorld setContentSize:mapSize];
        positionWorld.position = CGPointMake(mapSize.width / 2, mapSize.height / 2);
        [rotateWorld addChild:positionWorld z:0];
        [self addChild:rotateWorld z:0];

        // Test enemy
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"EnemiesSpritesheet.plist"];
        spriteSheetNonPlayer = [[CCSpriteBatchNode  alloc] initWithFile:@"EnemiesSpritesheet.png"capacity:10];
        [positionWorld addChild:spriteSheetNonPlayer z:0];
        enemy = [[Enemy_01 alloc] initWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"enemy_01_01.png"]];
        enemy.position = CGPointMake(mapSize.width / 2, mapSize.height / 2);
        [spriteSheetNonPlayer addChild:enemy];
    }

    return self;
}

现在我希望我的敌人精灵出现在屏幕中间,但它没有,我不知道它是否显示。有趣的是,如果我将 positionWorld 从 CCNode 更改为包含 4000x4000 背景图像的 CCSprite,它可以完美运行,但为什么不使用设置了 contetSize 的 CCNode?如何让它与 CCNode 一起工作?

谢谢索伦

4

1 回答 1

0

您需要为 CCNode 设置anchorPointccp(0.5,0.5)

rotateWorld.anchorPoint = ccp(0.5f,0.5f);
positionWorld.anchorPoint = ccp(0.5f,0.5f);

CCSprite 在其init方法内部做同样的事情(第 149 行CCSprite.m)。

于 2011-11-08T08:42:54.327 回答