TouchesMoved CGPoint Move Vertically

Discussion in 'iOS Development' started by ipodmail09, Dec 31, 2009.

  1. ipodmail09

    ipodmail09 Member

    Joined:
    Mar 13, 2009
    Messages:
    269
    Likes Received:
    0
    Device:
    2G iPod touch
    ok i am making a simple game.. now i have already worked out how to move the car horizontally all i need to know is how to move it vertically

    here is the code...

    [OBJC]- (void)touchesMoved

    Please Register or Log in to view images

    NSSet *)touches withEvent

    Please Register or Log in to view images

    UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    CGPoint xLocation = CGPointMake(location.x,redcar.center.y);
    redcar.center = xLocation;
    }[/OBJC]


    i have already played around with the xloaction and the y if i change it around i get the car going diagonally can anybody shine a light in this direction
  2. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    [OBJC]
    - (void)touchesMoved

    Please Register or Log in to view images

    NSSet *)touches withEvent

    Please Register or Log in to view images

    UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    CGPoint newCenter = CGPointMake(location.x, location.y);
    redcar.center = newCenter;
    }
    [/OBJC]

    This will set the center of redcar just to the location of the touch in your touch.view.

    If you only want to move vertically then use this:
    [OBJC]
    CGPoint newCenter = CGPointMake(redcar.center.x, location.y);
    [/OBJC]

    You should now be able to understand what this code does.

Share This Page