[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Xcode/IB NIB files and Chipmunk

Xcode/IB NIB files and Chipmunk

Official forum for the .

Xcode/IB NIB files and Chipmunk

Postby crm357 » Sun Feb 12, 2012 6:51 pm

I'm developing a child's book using animated characters in views that turn into pages via UIPageViewController. Because of the complex nature of the characters I'm using IB and NIB files to layout these characters, with IBOutlets used to access those elements that I want to animate with joints, springs, etc.

The demos that come with Chipmunk tend to create the visual elements that get animated programmatically but for the complex set of characters I'm chartered to build I really need to use IB.

Should I be using NIBs and associated IBOutlets with Chipmunk, or is it better to pass on NIBS and gen elements to be managed by Chipmunk programmatically?

Does anyone have any demos/examples that layout elements (images) in NIB files and "manages" their behavior with Chipmunk?

[It would be really helpful if SimpleObjectiveChipmunk could be altered using a NIB for the UIButton it uses and
demonstrate how to perform the physics with the NIB button]
crm357
 
Posts: 5
Joined: Sat Feb 04, 2012 3:41 pm

Re: Xcode/IB NIB files and Chipmunk

Postby slembcke » Sun Feb 12, 2012 11:45 pm

Yeah, it's certainly possible to do, and wouldn't be terribly hard. In the Simple Objective Chipmunk tutorial it creates a button and sets the position of it in code, but you could just as easily create the body and shape from UIView parameters in an awakForNib method. Set the position of the body from the view's center, and make the shape based on the bounds of the view.

I don't really have a lot of examples showing how to use Chipmunk this way because not a lot of people want to use Chipmunk with UIKit. UIKit works OK for small games (or books even) with a small number of objects on the screen, but it's performance doesn't really scale.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Xcode/IB NIB files and Chipmunk

Postby crm357 » Tue Feb 14, 2012 2:14 pm

Thanks for the quick response and the insight re performance and UIKit. I will keep this in mind as I go.

However, I'm hitting another problem that I've not seen before. Below is the actual code section revealing the issue:
[yes, i could use this in an override of the init method, but does that explain the problem described here?]


static UIImageView *graphic;

-(id)initWithImage:(UIImageView *)image
{
if(self = [super init]) {
cpFloat mass = 1.0;
cpFloat moment = cpMomentForBox(mass,bounds.frame.size.width,image.bounds.size.height);
// create a chipmunk body
body = [[ChipmunkBody alloc] initWithMass:mass andMoment:moment];
// and relate it's position to the image placement in the NIB
body.pos = cpv(image.bounds.origin.x,image.bounds.origin.y);

// create the associated shape
shape = [ChipmunkPolyShape boxWithBody:body width:image.bounds.size.width height:image.bounds.size.height];

chipmunkObjects = [[NSArray alloc] initWithObjects:body,shape,nil];

// save the reference to the UIImageView for the affine transform update
graphic = image;
}
return self;
}

-(void)updatePosition
{
// comment the assignment and the image stays on the screen; uncomment the assignment and the UIImageView disappears. Why?
graphic.transform = body.affineTransform;
}


As the above comment states the assignment of the body's affine transform makes the UIImage disappear. What would make this happen?
crm357
 
Posts: 5
Joined: Sat Feb 04, 2012 3:41 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests