Mouse interaction

Share your projects and Chipmunk enhancements.

Mouse interaction

Postby supertommy » Sat Jun 14, 2008 8:55 am

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:

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.
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm

Re: Mouse interaction

Postby maximile » Sun Jun 15, 2008 5:26 am

Looks excellent. Really nicely written too.
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK

Re: Mouse interaction

Postby chipmunkuser » Mon Jul 14, 2008 12:30 am

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.
Posts: 19
Joined: Fri May 09, 2008 4:48 pm

Re: Mouse interaction

Postby supertommy » Mon Jul 14, 2008 1:53 am

You're going to have to use the latest version in svn for this.
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm

Re: Mouse interaction

Postby chipmunkuser » Sat Jul 19, 2008 4:07 pm

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?

Posts: 19
Joined: Fri May 09, 2008 4:48 pm

Re: Mouse interaction

Postby shafijami » Fri Dec 12, 2008 7:04 am

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...

Posts: 4
Joined: Fri Dec 12, 2008 6:53 am

Re: Mouse interaction

Postby JonKean » Fri Dec 18, 2009 4:34 pm

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.
User avatar
Posts: 1
Joined: Fri Dec 18, 2009 4:30 pm
Location: San Francisco, California

Re: Mouse interaction

Postby maz » Fri Feb 05, 2010 1:06 pm

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.
Posts: 12
Joined: Thu Feb 04, 2010 12:34 pm

Re: Mouse interaction

Postby Tam Toucan » Sat Feb 06, 2010 4:50 am

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
Tam Toucan
Posts: 141
Joined: Tue Jun 23, 2009 4:26 pm

Re: Mouse interaction

Postby slembcke » Sat Feb 06, 2010 11:48 am

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! ->
User avatar
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Community Creations

Who is online

Users browsing this forum: No registered users and 3 guests