English 中文(简体)
background moves together with image
原标题:

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.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;
}

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.





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签