2014-03-26 104 views
0

有沒有辦法將skphysics應用到動畫角色?好的,我讓我的播放器在屏幕上移動時播放動畫,下面是動畫代碼,但由於某些原因,當我想將動畫應用到物理上時,出現錯誤,指出數據類型錯誤。 發送'SKSpriteNode * _strong'到不兼容類型'CGRect'(aka'struct CGRect')的參數SpriteKit動畫物理

沒有聲望,我無法回答我自己的問題,所以我張貼在這裏。

實際上沒關係我不得不添加這個_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

當然,這種方案有可能崩潰當它運行 [SKPhysicsBody bodyWithCircleOfRadius:_Player]預計浮法不是SKPriteNode,你可能想要做的就是這行代碼更改爲以下:

SKPhysicsBody *MYPLAYER = [SKPhysicsBody bodyWithCircleOfRadius:_Player.size.width/2]; 
+0

方式的朋友感謝您的幫助,但通過我已經找到了答案,並回答了我自己的問題在原來的職位,但因爲我沒有足夠的聲譽我不能使用回答你的問題的功能,所以請不投我的問題因爲這會影響我的帳戶。謝謝。 – Ray

+0

我明白了,順便說一句,我不是那個投了票的人,作爲一個友善的姿態,我會爲你投票。 – rockstarr

+0

謝謝。順便說一句,我需要幫助與我設計的遊戲,我可以問你嗎? – Ray