how to move the object in specific locations.
for examples. am having one small bar(width=50, height=10). i have to move this like plunger manually. i want to move only in x cordinates ( limits is x=20(start point) to x=50(end point)) no moves on y coordinates. but its moving 50 to 10 after wards 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 );
//para3.contentSize/2
if (newY >67 )
para3.position = CGPointMake( 67, para3.position.y );
if (newY < 99)
para3.position = CGPointMake( 99, para3.position.y );
}
}
I hope I have understood the issue perfectly. What I would have done in such a scenario is to include Chipmunk framework in my Game and then make my Plunger and cannon as the Physics objects. Once that is done, the speed and direction (i.e. angle of projectile) can be controlled through the "ApplyImpulse" methods of the framework. The speed and angle would have been controlled by Physics itself once I would provide the initial values....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With