标签:实现 instant sla 技术 comment turn 方向 elf word
@property (weak, nonatomic) IBOutlet UIButton *bird;
@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *ices;
对于冰块的连线。由于我们这里的冰块有4块,所以我们直接连的是一个数组
@property (strong, nonatomic) UIDynamicAnimator *animator;
- (UIDynamicAnimator *)animator
{
if ( !_animator) {
_animator = [UIDynamicAnimator new];
}
return _animator;
}
- (IBAction)birdAction:(id)sender
{
// 给鸟和冰加入重力
NSMutableArray *tempArrM = [NSMutableArray array];
[tempArrM addObject:self.bird];
[tempArrM addObjectsFromArray:self.ices];
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:tempArrM];
[self.animator addBehavior:gravity];
// 给鸟和冰加入碰撞
UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:tempArrM];
[collision setTranslatesReferenceBoundsIntoBoundary:YES];
// 加入屏幕边缘碰撞
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.view.bounds];
[collision addBoundaryWithIdentifier:@"BoundsTest" forPath:path];
[self.animator addBehavior:collision];
/**
UIPushBehaviorModeContinuous, 持续的力
UIPushBehaviorModeInstantaneous 瞬间的力
*/
// 给鸟加入推力
UIPushBehavior *push = [[UIPushBehavior alloc] initWithItems:@[self.bird] mode:UIPushBehaviorModeInstantaneous];
// 力的方向
push.magnitude = 5.0;
push.angle = 2 * M_PI;
[self.animator addBehavior:push];
}
看一下效果:
能简单的实现 这个小游戏。大家能够自己把剩下的功能完好。谢谢
标签:实现 instant sla 技术 comment turn 方向 elf word
原文地址:http://www.cnblogs.com/gavanwanggw/p/7387754.html