私は本当にこれにこだわっています。私のアプリケーションは横向きで、1 つの画面で指示画像をスクロール可能にしたいと考えていました。この画像をスプライトとして追加しました。最初に他のサイトからスクロール効果を取得しようとしましたが、すぐにスプライト画像ではなく画面全体に対してスクロールが行われていることがわかりました。次に、スプライトをy軸(上下)にのみドラッグして、スクロール効果を実装することにしました。残念ながら、スプライトの一部 (高さ 320 ピクセルでのみ画面に表示される) のみがドラッグされ、スプライトの残りの部分が表示されないため、どこかで混乱しています。コードは次のとおりです。
私が持っている初期層関数で
//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;
}