Help with moving an object.

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

  1. fox10078 macrumors 6502

    fox10078

    Joined:
    Nov 6, 2009
    #1
    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?

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

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

    ulbador

    Joined:
    Feb 11, 2010
    #3
    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

    fox10078

    Joined:
    Nov 6, 2009
    #4
    Its anywhere on the screen.

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

Share This Page