I know that chipmunk use to have cpMouse to drag shapes. In version 5.0 chipmunk doesn't have this. How do you drag shapes in chipmunk now? I have searched everywhere for an answer and can find out how to. Please help!?!?
Where Did cpMouse Go in Chipmunk?!?
(9 posts) (5 voices)-
Posted 1 year ago #
-
I'm not sure about your specific question, but when I needed to drag shapes by touch I looked at the pong-like test app in the cocos2d distribution.
Posted 1 year ago # -
It is not recommended to use cpMouse anymore. cpMouse used solid joints, which is not really a safe or good way to do things (objects will snap to position with an unlimited amount of force). Scott reworked the constraints system in chipmunk 5, implementing nice stuff like force limits, as well as some built in code for doing mouse like stuff with a greater degree of control. Check out the chipmunk demos, which feature plenty of examples of this.
Posted 1 year ago # -
Wheres the examples. I can't find the code.....
Posted 1 year ago # -
Build the chipmunk demo that comes with the chipmunk source (available at: http://code.google.com/p/chipmunk-physics/ )
It builds for Mac OS, not iPhone, but what you need to do on the chipmunk side of tings is exactly the same. Just watch for touches instead of mouse clicks.
Posted 1 year ago # -
there is an updated version that works with Chipmunk 5.0+
http://www.slembcke.net/forums/viewtopic.php?f=6&t=196&p=3690&hilit=cpmouse#p3690
Posted 1 year ago # -
I have added that in my project. A little buggy. I did as it said on the forums to do. But when I just click down on an object, it moves about 20 pixels to the right or the left and then zooms back to the touch location. I'm not sure why it works like this, but it does. Do you know whats wrong or how to fix it?
Here's the code I am using:
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { mouse = cpMouseNew(space); for(UITouch *touch in touches) { CGPoint location = [touch locationInView: [touch view]]; location = [[CCDirector sharedDirector] convertToGL: location]; cpMouseMove(mouse, cpv(location.x, location.y)); cpMouseGrab(mouse, cpv(location.x, location.y), YES); } } -(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { for(UITouch *touch in touches) { CGPoint location = [touch locationInView: [touch view]]; location = [[CCDirector sharedDirector] convertToGL: location]; cpMouseMove(mouse, cpv(location.x, location.y)); cpMouseGrab(mouse, cpv(location.x, location.y), NO); } } - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { for(UITouch *touch in touches) { CGPoint location = [touch locationInView: [touch view]]; location = [[CCDirector sharedDirector] convertToGL: location]; cpMouseDestroy(mouse); } }and then also if you drag quick enough (which isn't very quick), it will lose the grip on the object it is holding.
Posted 1 year ago # -
SDK: you call mouse grab on touches moved, if you go too fast it will grab nothing.
- (void)ccTouchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{ UITouch *myTouch = [touches anyObject]; CGPoint location = [myTouch locationInView: [myTouch view]]; location = [[CCDirector sharedDirector] convertToGL: location]; //move the nouse to the click cpMouseMove(mouse, cpv(location.x, location.y)); if(mouse->body == nil){ cpMouseGrab(mouse, cpv(location.x, location.y), 0); } }From a new project I'm working on, the source is available here: http://github.com/orta/kerchink - it's still quite C based, like my earlier example Grabbed, but its using cocos2d 0.99 and a bit simpler.
Posted 1 year ago # -
Wow. Thanks. Works perfectly now. Except when you first click on the object, it moves to the side about 20 pixels to the right. I new that something was wrong in the cpMouseGrap code.
Posted 1 year ago #
Reply
You must log in to post.