【发布时间】:2013-02-21 08:23:52
【问题描述】:
我遇到了一些 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 以外的任何其他方法中,它都可以在设备和模拟器上运行。
这对我来说可能是一个愚蠢的错误(我希望如此),因为这是我的第一个项目。
【问题讨论】:
-
您在哪里更新_prevTouch?设置断点,查看d的值,应该是0。
-
@LearnCocos2D _prevTouch 已在 ccTouchesMoved 方法中更新,很抱歉我剪掉了一些代码以保持简短。
标签: cocos2d-iphone ios-simulator ccsprite