Trying to move UIKit components with Chipmunk physics..

Official forum for the Chipmunk2D Physics Library.
lchallenge
Posts: 19
Joined: Tue Dec 04, 2012 6:05 am
Contact:

Trying to move UIKit components with Chipmunk physics..

Post by lchallenge »

I'm relatively new to programming in general, and began with iOS. I have a basic understanding of C, but the majority of my learning goes into Objective-C.

As such, I'm trying to create a basic Chipmunk-enabled app that will allow me to flick some UIImages around the screen and have them bounce off the edges, and off each other.

The tutorials on the site are literally all geared towards the paid Objective-C library, which I'd love to use, but as a hobbyist, simply can't afford to buy.

Is there a simple, step-by-step guide to creating a basic Chipmunk environment on iOS, using the free C library? I've found some old tutorials but they seem to use older versions of Chipmunk and I've had dozens of errors when trying to build them at various stages.

My project doesn't use cocos2d either, and almost every other tutorial I've found requires you to be using cocos2d to touch Chipmunk, which I don't really need/want to do.

Any way I can proceed, here? In fairness to Chipmunk, Box2D seems just as poorly-explained to beginners. I realise it may not be aimed at them, but still..
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by slembcke »

Actually I've been working on some new tutorial content lately and have a project that has variations for different combinations of Cocos2D, UIKit, Chipmunk and Chipmunk Pro.

https://github.com/slembcke/ChipmunkColorMatch

The source is fairly well commented. I'm in the process of writting tutorial articles too, but those aren't complete yet.

You can get pretty far with Chipmunk and UIKit, but I don't know of a good way to do debug rendering of the physics which is very helpful for troubleshooting when the physicsn don't seem to
One up right. You'll also find that UIKit's performance doesn't scale as well as the competition as it wasn't really meant as a sprite rendering lib.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
lchallenge
Posts: 19
Joined: Tue Dec 04, 2012 6:05 am
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by lchallenge »

That'll be fine, I'm trying to do something stupidly simple (have some UIButtons float loosely around the screen and bounce off each other / screen edges.

Hopefully the UIKit and non-pro tutorial will help, I'll keep an eye out for it. Thanks, much appreciated.
lchallenge
Posts: 19
Joined: Tue Dec 04, 2012 6:05 am
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by lchallenge »

Hey, just wondering if the tutorials for these projects are any further along? Would be really helpful.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by slembcke »

I was sick for most of last week so only the Cocos2D/Chipmunk Pro tutorial is done.

Like I said before though, the code has been done and well commented for over a week now. It's also only a couple hundred lines total so it shouldn't be hard follow along with.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
lchallenge
Posts: 19
Joined: Tue Dec 04, 2012 6:05 am
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by lchallenge »

I've been doing my best, but as someone new to programming, there's a lot of stuff that's quite a wide leap, and trying to re-create the code on my own gives a lot of errors it's quite tricky to track down.
lchallenge
Posts: 19
Joined: Tue Dec 04, 2012 6:05 am
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by lchallenge »

I'm having trouble understanding how I'd alter the gravity so that the objects don't simply fall to the bottom of the view. I'm trying to make them gently float around the view, as if seen from above, not on-side. Any tips on how I might modify this example to do that?
lchallenge
Posts: 19
Joined: Tue Dec 04, 2012 6:05 am
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by lchallenge »

Could you also explain why removing fg.png stops the balls appearing? I don't see any reference to it at all in the code so I don't see how it affects anything else.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by slembcke »

If you want the objects to float around set gravity to (0, 0). It defaults to zero actually, so you really just need to remove the line that sets gravity.

fg.png used in the .xib file that sets up the initial view controller. When adding balls to the view, it tells them to be added underneath the foreground. If you remove fg.png the .xib won't load correctly and will probably be telling it to add the balls under "nil". I have no idea what that does, but it sounds like it causes it to not add them at all, or add them behind the background.

So I don't mean to sound discouraging, but if you are new to programming, attempting to make two fairly complicated libraries (a math heavy one and a UI framework) might not be the best starter projects. Chipmunk on it's own isn't that interesting, so you might want to make sure you are comfortable with UIKit and C/Objective-C before diving into a project like this.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
lchallenge
Posts: 19
Joined: Tue Dec 04, 2012 6:05 am
Contact:

Re: Trying to move UIKit components with Chipmunk physics..

Post by lchallenge »

I'm comfortable enough with UIKit and this kind of work, it's just using a C-based library that's throwing me off a little. I noticed that you put the tutorial online for this, but it only covered the Pro version of Chipmunk, and using cocos2d, meaning it's even tougher for me to follow along since it's referring to cocos objects I don't have access to, and Pro objects I don't have access to either. I understand that you're pushing the paid versions, and it's entirely understandable that you'd do so since they're paying your salary, but a lot of us newbies are being left in the dark, to some extent.

Is there a tutorial in the works for the free version of Chipmunk, and the UIKIt components? I'm still struggling to grasp a lot of what's happening, where things are set, at what position the balls are being generated so that they fall into the view, etc.
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 14 guests