Help with moving an object.

Discussion in 'iOS Programming' started by fox10078, Dec 9, 2010.

  1. fox10078 macrumors 6502


    Nov 6, 2009
    Hello, this is the code im using currently to move my ship along an X-axis, right now it responds to any touch on the screen and automatically centers on the Y-axis of were the touch is located. Now I want it to only respond to touches on the ship, how would I do this?

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    	UITouch *touch = [[event allTouches] anyObject];
    	CGPoint location = [touch locationInView:touch.view];
    	CGPoint xLocation = CGPointMake (location.x,; = xLocation;
    	info.text = nil;
  2. Comrade Yeti macrumors newbie

    Nov 3, 2010
    Test to see if the touch is inside a rect surrounding your ship?
  3. ulbador macrumors 68000


    Feb 11, 2010
    What exactly is the ship object?

    If it's a basic UIImageView or something, you can just subclass it and put the touches code in that.
  4. fox10078 thread starter macrumors 6502


    Nov 6, 2009
    Its anywhere on the screen.

    It is a Image view, I'll try that thanks.

Share This Page