Mouse interaction

Share your projects and Chipmunk enhancements.
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Mouse interaction

Post by supertommy »

I wrote a piece of code the other day, which may turn out to be useful to some of you. I basically wanted the objects in my world to be more interactive. So that I could move stuff around and impart velocity and spin on them by dragging and releasing the mouse. Previously I had been limited to initialising my world in code, and then running it to see the physics, but that got old real quick if I was experimenting with something.

The result looks like this: http://www.youtube.com/watch?v=nBwK3pY25Mo

Turns out it's quite fun to play around with those objects - especially after I added the basketball hoop. It's almost like a little game already.

The attached code is written in the same style as chipmunk and I've put the same license on it. It'll only work with the svn version of chipmunk, though.
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Mouse interaction

Post by maximile »

Looks excellent. Really nicely written too.
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Re: Mouse interaction

Post by chipmunkuser »

There's a body->data access. I know there's a shape->data access but there's no data member in the body in my version of Chipmunk.
Guess I'll have to see if there's been an update.
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Mouse interaction

Post by supertommy »

You're going to have to use the latest version in svn for this.
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Re: Mouse interaction

Post by chipmunkuser »

So I updated to the latest version and folded in your source files.

Created the mouse object and moved it to new positions as that changes. It displays fine
but it never grabs anything.

If I review the mouseOver function one item is always an object I have jointed to the static space.
The other is always the mouse. No other objects seem to be checked for mouse over. The BoundingRects also don't relate to the moving
object. They always read the same center position even though they're moving. (i.e. the mouse is always the size I set it)
Am I missing an additional init or setup?

Thanks.
shafijami
Posts: 4
Joined: Fri Dec 12, 2008 6:53 am
Contact:

Re: Mouse interaction

Post by shafijami »

Hi Supertommy

I'm new to IPhone and Chipmunk. I want to do in my current game project almost same thing (with only difference i.e. after touching any side ball will bounce only once like using striker in Carom board game. So could you please help me for a small project (Xcode version) as I'm facing this hindrance in my project? I'll very thankful to you. Its critical. I'm avidly waiting of your reply. Please...

Shafi
User avatar
JonKean
Posts: 1
Joined: Fri Dec 18, 2009 4:30 pm
Location: San Francisco, California
Contact:

Re: Mouse interaction

Post by JonKean »

cpMouse is broken with the latest 5.0 Chipmunk release, and I've fixed it up to work again.
Note that shapes must have their layer set to GRABABLE_MASK_BIT for cpMouse to grab them.
maz
Posts: 12
Joined: Thu Feb 04, 2010 12:34 pm
Contact:

Re: Mouse interaction

Post by maz »

If anyone is using cpMouse, make sure that you have [window setMultipleTouchEnabled:NO];

Having it set to YES will cause errors and crashes. I found this out the hard way.
User avatar
Tam Toucan
Posts: 141
Joined: Tue Jun 23, 2009 4:26 pm
Contact:

Re: Mouse interaction

Post by Tam Toucan »

I don't code on the iPhone, but what you're saying isn't strictly true....cpMouse is pure C code using chipmunk. It knows nothing about multiple touches or the iPhone. Therefore the problem is how to use cpMouse with mutiple touch enabled, i.e. cpMouse can be used with multiple touch, you just have to use it correctly.

Just guessing, since I know nothing about what multi-touch does, but if you only created one mouse object (cpMouseAlloc), but allowed multiple grabs then you would likely get crashes. i.e. if multi-touch lets you have "two mouse pointers" then your would need two cpMouse objects or would need to have extra code to handle it etc.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Mouse interaction

Post by slembcke »

Well, it's basically as if you got two mousedown events in a row, then two mouseup events in a row. So my guess is what's happening is that it's creating the joint, adding it to the space, overwritting that joint, adding the new one to the space, then attempting to remove and free the second one twice. Bam.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests