我遇到了一些 cocos2d 代码的问题,它在模拟器上运行良好(意味着在这种情况下,当我触摸和滚动时精灵正在移动)但它在我的 ipod 上不起作用 ccTouchesMoved 在两者上都被调用,但是精灵只在模拟器中移动
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;
}
顺便说一句,如果我执行“gradA.position = ccp(0, gradA.position.y - d);” 在 ccTouchesMoved 以外的任何其他方法中,它都可以在设备和模拟器上运行。
这对我来说可能是一个愚蠢的错误(我希望是这样),因为这是我的第一个项目。