开发者

background moves together with image

开发者 https://www.devze.com 2022-12-11 20:44 出处:网络
I have 4 images and a background. I already about to animate the image to move accordingly. But the back ground is not moving. I am not sure how to make the background move accordingly to the movement

I have 4 images and a background. I already about to animate the image to move accordingly. But the back ground is not moving. I am not sure how to make the background move accordingly to the movement of the images. Because each of the images moves differently.

this is first image move:

- (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];  
}

this is second image:

- (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];  
}

this is the initializer of the background

- (id)init
{
    if (self = [super init])
    {
        Sprite *background = [Sprite spriteWithFile:@"background.png"];
        background.positio开发者_JAVA技巧n = CGPointMake(240,160);
        [background runAction:[FadeIn actionWithDuration:1]];
        [self addChild:background];

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

I appricate anyone's help


Your code is formatted (here) in a way that makes it difficult to read, however it seems you simply haven't told teh backbground to move. You just tell it:

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

So you are telling it to fade in, but not to move.

Which just tells it to fade in. You have to fix your code formatting to be able tell more.

0

精彩评论

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