我真的被困在这个上面。我的应用程序是横向视图,在一个屏幕上,我希望我的说明图像可以滚动。我已将此图像添加为精灵。首先,我试图从其他网站获得滚动效果,但很快我看到滚动是为完整屏幕而不是精灵图像完成的。然后,我通过拖动精灵只在y轴上(上和下)来实现滚动效果。不幸的是,我在某处弄乱了某些东西,因为只有一部分精灵(屏幕上只显示高度为320像素)被拖动,剩下的精灵没有显示出来。该代码是在init层功能如下在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;
}
“ccp(instructionsImage.position.y,...)”应该是“ccp(instructionsImage.position.x,...)”,但是,这种方法是有效的。 – Evan 2010-05-13 22:37:23