Need help - xcode: mouse follow easing

Discussion in 'iPhone/iPad Programming' started by newbie80, Mar 31, 2011.

  1. newbie80, Mar 31, 2011
    Last edited: Apr 1, 2011

    macrumors member

    Joined:
    Mar 2, 2011
    #1
    Hi guys,

    I have Xcode question.
    I would like to know when I touch anywhere on ipad/iphone, the picture on the screen will slowly move to the place that I touched. How do I do that?

    I manage to find flash script CS5 for iphone only, but I couldn't find any samples for xcode.

    Hope anyone could help me here. Thank you. :)

    It looks something like this:
    http://asgamer.com/2009/as3-character-movement-following-mouse-with-easing
    But I don't want it to follow the pointer wherever I move, when I touch on or click on that place, then the image move to that place and stop.
     
  2. thread starter macrumors member

    Joined:
    Mar 2, 2011
    #2
    Now how do I make the player stop at the point that I touched?

    Code:
    @synthesize player;
    CGPoint Destination;
    CGFloat xamt,yamt;
    CGFloat speed = 50;
    
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        UITouch *touch = [[event allTouches] anyObject];
    	CGPoint location = [touch locationInView:self.view];
        
        Destination = location;
        xamt = ((Destination.x - player.center.x) / speed);
    	yamt = ((Destination.y - player.center.y) / speed);
        
        [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
        
    }
    
    - (void)onTimer{
    player.center = CGPointMake(player.center.x+xamt, player.center.y+yamt);
        if (player.center.x > 320 || player.center.x < 0) {
            xamt = -xamt;
        }
        if (player.center.y > 480 || player.center.y < 0) {
            yamt = -yamt;
        }
       
    }
    
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
  4. thread starter macrumors member

    Joined:
    Mar 2, 2011
    #4

Share This Page