我在我的项目中创建了一个简单的sks
粒子文件,我想知道 A:如何在我的视图中实现此粒子以及如何添加适当的参数,以便粒子沿设备所在的方向行进, (例如与 iOS7 动态壁纸非常相似),所以在我的情况下,如果我有石头直下而下并且设备向右倾斜,那么石头应该以不同的角度开始下落。我真的很感激一些建议。
问问题
166 次
1 回答
0
我实际上也在考虑将这种效果应用到我自己的游戏中。这是一个粗略的答案,我实际上并没有尝试将这两个元素结合起来,但它肯定会给你一些指导。
@property (strong,nonatomic) SKEmitterNode * starEmitter;
@property (strong,nonatomic) CMMotionManager * self.motionManager;
// Create your emitter
NSString *starPath = [[NSBundle mainBundle] pathForResource:@"startButtonDisappear" ofType:@"sks"];
self.starEmitter = [NSKeyedUnarchiver unarchiveObjectWithFile:starPath];
// Create a motion manager
self.motionManager = [CMMotionManager new];
[self.motionManager startAccelerometerUpdates];
在您的更新方法中,计算重力矢量并指定发射器的加速度属性。
- (void)update:(NSTimeInterval)currentTime {
CMAccelerometerData* data = self.motionManager.accelerometerData;
// You really don't want NSLogs in this method in a release build, by the way
NSLog(@"x [%2.1f] y [%2.1f] z [%2.1f]",data.acceleration.x,data.acceleration.y,data.acceleration.z)
CGVector gravity;
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) {
gravity = CGVectorMake(data.acceleration.x, data.acceleration.y);
} else {
gravity = CGVectorMake(-data.acceleration.x, -data.acceleration.y);
}
CGFloat tmp = gravity.dy;
gravity.dy = gravity.dx;
gravity.dx = tmp;
// self.physicsWorld.gravity = gravity;
self.starEmitter.xAcceleration = gravity.x;
self.starEmitter.yAcceleration = gravity.y;
NSLog(@"Emitter acceleration set to [%+4.2f,%+4.2f]",gravity.dx,gravity.dy);
}
于 2014-03-13T13:24:09.750 回答