2014-03-03 37 views
1

爲什麼我不能在帶有(id)引用的對象上使用zRotation?我可能把這個問題的結構錯了,在這種情況下我很抱歉。通過方法在對象上生成zRotation - sprite工具包

這是代碼。

-(void)moveAlien:(id)alien :(CGPoint)startPos :(CGPoint)stopPos :(float) speed 
{ 
    float katetX = startPos.x - stopPos.x; 
    float katetY = startPos.y - stopPos.y; 

    // 
    alien.zRotation = atan(katetX/katetY); //This doesn't work 
    // 



    SKAction *moveAlien = [SKAction moveTo:stopPos duration:speed]; 
    [alien runAction:moveAlien]; 
} 
  • 住宅 'zRotation' 在類型的對象__strong ID「

我在做什麼錯沒有發現?我怎樣才能使它工作?

+0

大的第一篇文章,歡迎到現場 –

回答

0

發生這種情況是因爲idNSObject*相同。並且NSObject*沒有名爲zRotation的屬性。您可能要轉換的變量,像:

((MyAlienClass *)alien).zRotation = atan(katetX/katetY); 

甚至更​​好,使參數更具體一點:

-(void)moveAlien:(MyAlienClass *)alien :(CGPoint)startPos :(CGPoint)stopPos :(float) speed 

PS: 中的ObjectiveC你通常描述與參數功能的名稱,如下所示:

-(void)moveAlien:(MyAlienClass *)alien from:(CGPoint)startPos to:(CGPoint)stopPos withSpeed:(float)speed 

因爲調用看起來會好得多:

[this moveAlien:alien from:CGPointMake(0,0) to:CGPointMake(10,0) withSpeed:3.5] 

比:

[this moveAlien:alien :CGPointMake(0,0) :CGPointMake(10,0) :3.5]