Sprite position not working in Objective-C, Xcode

≡放荡痞女 提交于 2019-12-25 07:54:23

问题


It has been a year or so since I've used Objective-C and I must have forgot something because this is stumping me. I didn't use a for loop because I wanted a delay, but I logged all these variables, r is a float, j is an integer. r and j were initialized to 0.

-(void)fire{
    r = j;
    if (j < 80) {

        j = j + 1;
        bullet.position = CGPointMake(2*r, 15);

        NSLog(@"r is %f", r);
        NSLog(@"j is %i", j);
        NSLog(@"position is %f, %f",bullet.position.x, bullet.position.y);

        NSLog(@"x is, %f", r/8);
        [self performSelector:@selector(fire) withObject:nil afterDelay:.05];
    }
}

I get 80 readouts in the log and this is one of them, arbitrarily when r is 70:

r is 70.000000
j is 71
position is 0.000000, 0.000000
x is, 8.750000

So why is the position always (0,0) when I am clearly telling it to be (2*r, 15)?

By the way, here is the code I initialize the bullet with

bullet = [SKSpriteNode spriteNodeWithImageNamed:@"missile"];
bullet.xScale = 1;
bullet.yScale = 1;
bullet.position = CGPointMake(67, 148);
bullet.zRotation = M_PI;

[self addChild:bullet];

来源:https://stackoverflow.com/questions/37151659/sprite-position-not-working-in-objective-c-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!