Resolved problem with background moving?

Discussion in 'iOS Programming' started by larswik, Jul 4, 2014.

  1. larswik, Jul 4, 2014
    Last edited: Jul 5, 2014

    larswik macrumors 68000

    Sep 8, 2006
    I am working with Cocos2d and I got this strange but simple problem. I wanted to slide the CCSptire called backgroundView 1 pixel every time the update loop is called. When I ran the program the background was gone so I added a NSLog to test the results. I then removed the code + 1 from the update method, "backgroundView.boundingBox.origin.x + 1". So now every time the update method is called the boundingbox.origin X and Y should remain the same. But the NSLog, displayed below, shows that it is still moving when it should remain the same? The PNG image is 1136 x 640. The image is moving -568 each loop, which is the hight of the iPhone.

    What have I missed here?

    - (id)init
        // Apple recommend assigning self with supers return value
        self = [super init];
        if (!self) return(nil);
        [B][self pageSetup];[/B]
    	return self;
        backgroundView.position = ccp([B]backgroundView.boundingBox.origin.x[/B], backgroundView.boundingBox.origin.y);
        NSLog(@"x%.0f", backgroundView.boundingBox.origin.x);
        backgroundView = [CCSprite spriteWithImageNamed:@"bgTest.png"];
        backgroundView.position = ccp(0, 320);
        [self addChild:backgroundView];
  2. larswik thread starter macrumors 68000

    Sep 8, 2006
    Jeese.... Why do I always find the answer right after I hit the submit button...

    The problem was object.boundingbox.origin.x. I should have written object.position.x instead.
  3. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Consider it evidence that rubber duck debugging works.

    At least you posted code, so +1 for that.

    Remember to use the "Resolved" prefix.

Share This Page