2009-11-13 3 views
2

나는 정말 여기에 붙어 있습니다. 내 응용 프로그램은 가로보기이며 한 화면에서 내 지침 이미지를 스크롤 할 수 있기를 원합니다. 이 이미지를 스프라이트로 추가했습니다. 먼저 스크롤 효과를 다른 사이트에서 사용할 수있게하려고했지만 곧 스크롤이 스프라이트 이미지가 아닌 전체 화면에서 수행되는 것을 보았습니다. 그런 다음 스프라이트를 y 축 (위아래)으로 드래그하여 스크롤 효과를 구현했습니다. 불행히도 나는 어딘가에있는 것들을 엉망으로 만들고있다. 왜냐하면 스프라이트의 한 부분 (높이 320 픽셀의 화면에만 표시됨)이 드래그되고 스프라이트의 나머지 부분이 보이지 않기 때문이다. 초기화 층 기능에COCOS2D의 스크롤 효과와 같이 특히 큰 스프라이트를 위아래로 드래그

을 다음과 같이 코드는 내가

//Add the instructions image 

instructionsImage = [Sprite spriteWithFile:@"bkg_InstructionScroll.png"]; 
instructionsImage.anchorPoint = CGPointZero; 
[self addChild:instructionsImage z:5]; 
instructionsImage.position = ccp(40,-580); 
oldPoint = CGPointMake(0,0); 
self.isTouchEnabled = YES; 

//The touch functions are as follows 
- (BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
UITouch *touch = [touches anyObject]; 

// Move me! 
if(touch && instructionsImage != nil) { 
    CGPoint location = [touch locationInView: [touch view]]; 
    CGPoint convertedPoint = [[Director sharedDirector] convertCoordinate:location]; 

    CGPoint newPoint = CGPointMake(40, (instructionsImage.anchorPoint.y+ (convertedPoint.y - oldPoint.y))); 
    instructionsImage.position = newPoint; 
    return kEventHandled; 
} 
return kEventIgnored; 
} 

//The other function 
- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
UITouch *touch = [touches anyObject]; 

// Move me! 
if(touch && instructionsImage != nil) { 
    CGPoint location = [touch locationInView: [touch view]]; 
    CGPoint convertedPoint = [[Director sharedDirector] convertCoordinate:location]; 
    oldPoint = convertedPoint; 
    return kEventHandled; 
} 

return kEventIgnored; 
} 

답변

0

당신의 접근 방식은 일반적으로 정확해야합니다.

코드는 제대로 포맷하지 않은, 당신은 증상이 문제가 정확히 무엇에 명확하지 않았다 ...

을하지만 ccTouchesMoved에 수학이 잘못된 것처럼 나타납니다. 앵커 포인트는 위치 및 회전 앵커가 발생하는 이미지 내의 비율이기 때문에 걱정하지 않습니다. 당신이하는 것처럼, 생성자에서 의미가있는 것은 무엇이든 설정하지만 이후에는 참조 할 필요가 없습니다.

바로 스프라이트에 움직임을 추가하십시오 :

deltaY에 = convertedPoint.y - oldPoint.y;

이제 손가락이 위아래로 움직이는 픽셀 수를 알 수 있습니다.

다음에 대한 oldPoint 데이터를 재설정

oldPoint.y = convertedPoint.y; 이제

스프라이트이 델타를 적용

instrucitonsImage.position = CCP (instructionsImage.position.y, instructionsImage.position.y + 델타);

해야합니다.

+0

"ccp (instructionsImage.position.y, ...)"는 "ccp (instructionsImage.position.x, ...)"가되어야하지만 예,이 방법이 효과적입니다. – Evan