我遇到了一些cocos2d代碼的問題, 它在模擬器上運行正常(這意味着在我觸摸和滾動時精靈正在移動)但它並沒有對我的iPod 工作ccTouchesMoved被稱爲兩個,但如果我做了「gradA.position = CCP(0,gradA.position.y精靈在模擬器只能移動Cocos2d iphone:改變CCSprite.position在模擬器上工作,但不在設備上
CCSprite *gradA = [CCSprite spriteWithFile:@"grad.png"];
gradA.anchorPoint = ccp(0, 0);
gradA.position = ccp(0, 0);
[...]
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//NSLog(@"ccTouchesMoved called");
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
int d = (_prevTouch.y - location.y);
// This code should make the sprite moving
// And it does on the simulator but not on my ipod
gradA.position = ccp(PARALAX_X, gradA.position.y - d);
_prevTouch = location;
}
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
_firstTouch = location;
}
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
_lastTouch = location;
}
BTW - d);「 除了ccTouchesMoved之外,它可以在設備和模擬器上工作。
這可能是一個愚蠢的錯誤(我希望它)在我身邊,因爲這是我的第一個項目。
你在哪裏更新_prevTouch?設置一個斷點並檢查d的值,可能爲0. – LearnCocos2D 2013-02-21 09:54:18
@ LearnCocos2D _prevTouch已在ccTouchesMoved方法中更新,對不起,我切斷了一些代碼以保持簡短。 – jrmgx 2013-02-21 12:21:45