일부 cocos2d 코드에 문제가 발생했습니다. 시뮬레이터에서 잘 실행됩니다 (이 경우 터치 및 스크롤 할 때 스프라이트가 움직이는 경우를 의미 함) 하지만 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가 아닌 다른 방법으로 장치 및 시뮬레이터에서 작동합니다.
내 첫 번째 프로젝트이기 때문에 내 측면에서 바보 같은 실수가 될 수 있습니다. 나는 (ccTouchesMoved에서) 지금 내 스프라이트를 이동하고 방법은 다음과
어디에서 _prevTouch를 업데이트합니까? 중단 점을 설정하고 d의 값을 확인하십시오. 아마도 0입니다. – LearnCocos2D
@ LearnCocos2D _prevTouch가 ccTouchesMoved 메소드에서 업데이트되었습니다. 코드를 짧게 유지하는 것이 유감입니다. – jrmgx