有没有办法将skphysics应用于动画角色?好吧,当我在屏幕上移动时,我的播放器播放动画,下面是动画代码,但出于某种原因,当我想将物理应用于动画时,我收到错误的错误数据类型。 将'SKSpriteNode * _strong'发送到不兼容类型'CGRect'(又名'struct CGRect')的参数
没有声望,我无法回答我自己的问题所以我发布在这里。
实际上没关系,我必须添加这个_Player.frame,我希望这是正确的,并将物理学放在我的角色上。但是,如果我错了,请纠正我。感谢。
- (void) Player {
_Player = [SKSpriteNode spriteNodeWithImageNamed:@"bird"];
_Player.xScale = 0.88;
_Player.yScale = 0.88;
_Player.position = CGPointMake(100, 100);
[self addChild:_Player];
// 1
NSMutableArray *PlayerCh = [NSMutableArray arrayWithCapacity:2];
// 2
for (int i = 1; i < 2; i++) {
NSString *mytextureName = [NSString stringWithFormat:@"bird%d", i];
SKTexture *ItsTexture = [SKTexture textureWithImageNamed:mytextureName];
[PlayerCh addObject:ItsTexture];
}
// 3
for (int i = 2; i > 1; i--) {
NSString *mytextureName = [NSString stringWithFormat:@"bird%d", i];
SKTexture *ItsTexture = [SKTexture textureWithImageNamed:mytextureName];
[PlayerCh addObject:ItsTexture];
}
// 4
_PlayerAnimation = [SKAction animateWithTextures:PlayerCh timePerFrame:0.1];
// SKPHYSICS FOR PLAYER
SKPhysicsBody *MYPLAYER = [SKPhysicsBody bodyWithCircleOfRadius:_Player]; // I get a error here.
}
答案 0 :(得分:0)
当然这个程序在运行时必须崩溃 [SKPhysicsBody bodyWithCircleOfRadius:_Player]期望浮点数不是SKPriteNode,您可能想要做的是将此行代码更改为以下内容:
SKPhysicsBody *MYPLAYER = [SKPhysicsBody bodyWithCircleOfRadius:_Player.size.width/2];