我遇到了一些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