фон движется вместе с изображением

У меня есть 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;
}

я приму любую помощь


person Rocker    schedule 17.11.2009    source источник
comment
проверьте свое форматирование для второй половины кода, кажется, что он испорчен на полпути   -  person bguiz    schedule 17.11.2009


Ответы (1)


Ваш код отформатирован (здесь) таким образом, что его трудно читать, однако кажется, что вы просто не сказали фону двигаться. Ты просто скажи это:

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

Итак, вы говорите ему растворяться, но не двигаться.

Который просто говорит, что он исчезает. Вы должны исправить форматирование кода, чтобы иметь возможность рассказать больше.

person David Whatley    schedule 06.01.2010