背景与图像一起移动

时间:2009-11-17 04:59:32

标签: objective-c cocos2d-iphone

我有4张图片和一张背景。我已经准备动画图像以相应地移动。但背景并没有动。我不确定如何使背景相应地移动图像。因为每个图像的移动方式不同。

这是第一次移动图片:

- (void)loadIllustration1
{
    Sprite *illustration1 = [Sprite spriteWithFile:@"livraison01.png"];
    [illustration1 setTag:kTagIllustration1];   
    //illustration1.position = CGPointMake(540,-40);
    illustration1.position = CGPointMake(540,-40);
    illustration1.scale =1.14;
    id fade  = [FadeIn actionWithDuration:1];
    //id go    = [MoveTo actionWithDuration:2 position:CGPointMake(10,-10)];
    id go    = [MoveTo actionWithDuration:2 position:CGPointMake(10,-10)];
    id seq   = [Sequence actions: fade ,go , nil];      
    [illustration1 runAction:seq];
    [self addChild:illustration1];

    [NSTimer scheduledTimerWithTimeInterval:3.8 target:self selector:@selector(finishIllustrationAnimation1) userInfo:nil repeats:NO];  
}

这是第二张图片:

- (void)loadIllustration2
{
    Sprite *illustration1 = (Sprite *)[self getChildByTag:kTagIllustration1];
    if (illustration1 != nil) [self removeChildByTag:kTagIllustration1 cleanup:YES];
    Sprite *illustration2 = [Sprite spriteWithFile:@"livraison02.png"];
    [illustration2 setTag:kTagIllustration2];   
    illustration2.scale = 0.9;
    //illustration2.position = CGPointMake(460,135);
    //this will show the image from down right  to up left
    illustration2.position = CGPointMake(30,240);
    id fade  = [FadeIn actionWithDuration:1];
    //id go    = [MoveTo actionWithDuration:2 position:CGPointMake(20,305)];
    //this will show the image from down right  to up left
    id go    = [MoveTo actionWithDuration:2 position:CGPointMake(400,30)];  
    id seq   = [Sequence actions: fade ,go , nil];      
    [illustration2 runAction:seq];      
    [self addChild:illustration2];
    [NSTimer scheduledTimerWithTimeInterval:3.8 target:self selector:@selector(finishIllustrationAnimation2) userInfo:nil repeats:NO];  
}

这是背景的初始化器

- (id)init
{
    if (self = [super init])
    {
        Sprite *background = [Sprite spriteWithFile:@"background.png"];
        background.position = CGPointMake(240,160);
        [background runAction:[FadeIn actionWithDuration:1]];
        [self addChild:background];

        self.reader = [[BubbleReader alloc] initWithPlistFile:@"BubbleItems.plist"] ;
        currentIllustration = kTagIllustration1;
        [self loadIllustration];    
    }
    return self;
}

我嘲笑任何人的帮助

1 个答案:

答案 0 :(得分:0)

您的代码格式化(此处)的方式使其难以阅读,但似乎您根本没有告诉后台移动。你只需告诉它:

[background runAction:[FadeIn actionWithDuration:1]];

所以你要告诉它淡入,但不要动。

这只是告诉它淡入。你必须修复你的代码格式才能告诉更多。