Graphics Reference
In-Depth Information
self . shape -> data = ( __bridge void *) self ;
//set the body position to match view
cpBodySetPos ( self . body , cpv (frame. origin . x + frame. size . width / 2 ,
300 - frame. origin . y - frame. size . height / 2 ));
}
return self ;
}
- ( void )dealloc
{
//release shape and body
cpShapeFree ( _shape );
cpBodyFree ( _body );
}
@end
@interface ViewController ()
@property ( nonatomic , weak ) IBOutlet UIView *containerView;
@property ( nonatomic , assign ) cpSpace *space;
@property ( nonatomic , strong ) CADisplayLink *timer;
@property ( nonatomic , assign ) CFTimeInterval lastStep;
@end
@implementation ViewController
#define GRAVITY 1000
- ( void )viewDidLoad
{
//invert view coordinate system to match physics
self . containerView . layer . geometryFlipped = YES ;
//set up physics space
self . space = cpSpaceNew ();
cpSpaceSetGravity ( self . space , cpv ( 0 , - GRAVITY ));
//add a crate
Crate *crate = [[ Crate alloc ] initWithFrame : CGRectMake ( 100 , 0 , 100 , 100 )];
[ self . containerView addSubview :crate];
cpSpaceAddBody ( self . space , crate. body );
cpSpaceAddShape ( self . space , crate. shape );
Search WWH ::




Custom Search