affineTransform issue

Discuss any Chipmunk bugs here.
Post Reply
crm357
Posts: 5
Joined: Sat Feb 04, 2012 3:41 pm
Contact:

affineTransform issue

Post by crm357 »

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?]

Code: Select all

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?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: affineTransform issue

Post by slembcke »

Unfortunately UIKit elements don't all use the transform property quite the same way. From Apple's docs:
https://developer.apple.com/library/ios ... TP40006816

Make sure the view's center or the layer's anchor is where you think it should be, because that is what will match up with the body's position. I've noticed with some things it's not always set to be the real center of the object.
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 4 guests