2012-03-05 68 views
0

我有這個空間的功能,使得如果檢測到觸摸精靈招:如何使用cocos2d在觸摸時移動精靈?

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInView:[touch view]]; 
    location = [[CCDirector sharedDirector] convertToGL:location]; 

    car.position = ccp(0,10); 
} 

遊戲的符文,但是當我撫摸它凍結時,其意動車精靈畫面,感謝您幫幫我!!

+0

很難幫助您提供的信息:什麼是'凍結',你看到日誌中的錯誤,調試控制檯中的某種消息?此外,什麼是「汽車」對象,顯示您創建此對象的位置,並指定汽車iVar。在這段代碼中,所有的都是非常香草的,唯一能夠看到的'凍結'是當你試圖設置其位置時'汽車'被取消分配。 – YvesLeBorg 2012-03-05 05:27:58

回答

1

1的方式是

[car setposition:location]; 

它會直接把你的車停在你的觸摸。 其他方式是

[car runAction:[CCMoveTo actionWithDuration:1 position:location]]; 

檢查拼寫。我沒有IDE來檢查每個拼寫。 :) 希望這有助於