![]()
大.
现在,我想使用applyForce在它下降的同时向某个方向推动它.
不幸的是,无论我使用physicsBody.mass或physicsWorld.gravity有多小,或者我生成applyForce向量的大小 – applyForce向量似乎都被忽略了.
当我注释掉self.physicsWorld.gravity行时,我看到applyForce按预期工作
在应用重力的同时,如何使用applyForce实现“推动”物理体?
这是我的.h
// GameScene.h#import <SpriteKit/SpriteKit.h>@interface GameScene : SKScene@end
还有他们
// GameScene.m#import "GameScene.h"@interface GameScene ()@property NSMutableArray *bubblestopop;@end@implementation GameScene-(voID)dIDMovetoVIEw:(SKVIEw *)vIEw { /* Setup your scene here */ self.size = vIEw.bounds.size; self.physicsWorld.gravity = CGVectorMake(0,1.0); SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImagenamed:@"bubble"]; sprite.yScale = 0.5; sprite.xScale = 0.5; sprite.name = @"bubble"; sprite.position = CGPointMake(self.frame.size.wIDth / 2.0,self.frame.size.height / 2.0); SKPhysicsBody *physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.frame.size.wIDth]; physicsBody.mass = 0.02; [physicsBody applyForce:CGVectorMake(900,900)]; sprite.physicsBody = physicsBody; [self addChild:sprite];}@end解决方法 在Sprite Kit可以确定力如何影响它之前,身体需要在场景中.在将addChild添加到场景后,需要在物理主体上调用applyForce. 来自Apple的文档:
The physics simulation in Sprite Kit is performed by adding physics bodIEs to scenes. A physics body is a simulated physical object
connected to a node in the scene’s node tree. It uses the node’s
position and orIEntation to place itself in the simulation…Each time
a scene computes a new frame of animation,it simulates the effects
of forces and collisions on physics bodIEs connected to the node
tree. It computes a final position,orIEntation,and veLocity for
each physics body. Then,the scene updates the position and rotation
of each corresponding node [emphasis added].
此外,外部因素有助于物理机构如何受到力的影响.例如,在计算应用于物理主体的净力时,必须考虑重力,碰撞和力场(iOS 8).因此,在Sprite Kit可以确定力如何影响它之前,身体需要在场景中.
总结以上是内存溢出为你收集整理的ios – 为什么SKSpriteNode不响应applyForce或applyImpulse?全部内容,希望文章能够帮你解决ios – 为什么SKSpriteNode不响应applyForce或applyImpulse?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)