how to move an object in certain places.
for examples. am has one small bar (width = 50, height = 10). I have to move this as a plunger manually. I want to move only in x coordinates (limits x = 20 (start point) to x = 50 (end point)), does not move along y coordinates. but its moving from 50 to 10 after there was no movement.
coding: -
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (isPlaying) { UITouch *touch = [[event allTouches] anyObject]; touchPosition = [touch locationInView:touch.view]; if ( CGRectContainsPoint(para3.boundingBox,touchPoint) isDragging = YES; touchOffset = para3.position.y - touchPosition.y; } - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (isPlaying) { UITouch *touch3 = [[event allTouches] anyObject]; float distanceMoved = ([touch3 locationInView:touch3.view].y + touchOffset) - para3.position.y; float newY = para3.position.y + distanceMoved; if (newY > 67 && newY < 99) para3.position = CGPointMake(newY , para3.position.y );
objective-c iphone cocos2d-iphone sprite
Srinivas
source share