开发者

how can I recall a part of body in a method that would call after each second?

开发者 https://www.devze.com 2023-03-12 01:56 出处:网络
I am coding as follows -(void) moveMetho开发者_运维知识库d :(Paddle *) pad { float counter = 10;

I am coding as follows

-(void) moveMetho开发者_运维知识库d :(Paddle *) pad {
    float counter = 10;
    self.position = CGPointMake(80,counter);
}

Now I want increase counter with +5 after each one second, what should I do, so that object should move upside?


You could use below by declaring counter as static variable.

-(void) moveMethod :(id) sender {
    static float counter = 10;
    self.position = CGPointMake(80,counter);
    counter+=5;
}

Here is the timer

[NSTimer scheduledTimerWithTimeInterval:1.0f
    target:self
    selector:@selector(moveMethod:)
    userInfo:nil
    repeats:YES];
0

精彩评论

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