我正在使用 levelhelper 和偷偷摸摸的输入制作一个横向滚动游戏。我有几个问题。我在不同的图层上有偷偷摸摸的输入,我在使用 levelhelper 的视差滚动时遇到了问题。
我无法设法应用边界并正确移动图层。我将如何修复滚动?要在边界内并以角色为中心?
我在更新方法中有这两种方法
-(void) update:(ccTime)deltaTime{
[self applyJoystick:_leftJoystick forTimeDelta:deltaTime];
[self setViewpointCenter:hero.position];}
-(void)applyJoystick:(SneakyJoystick *)aJoystick forTimeDelta:(float)delta{
CGRect worldRect = [loader gameWorldSize];
CGPoint scaledVelocity=ccpMult(aJoystick.velocity, 90.0f);
CGPoint newPosition =ccp(hero.position.x+scaledVelocity.x*delta, hero.position.y +scaledVelocity.y *delta);
float posX = MIN(worldRect.origin.x + worldRect.size.width - hero.centerToSides, MAX(hero.centerToSides, newPosition.x));
float posY = MIN(worldRect.origin.y + worldRect.size.height - hero.centerToBottom, MAX(hero.centerToBottom, newPosition.y));
[hero setPosition:cpp(posX,posY)];}
-(void)setViewpointCenter:(CGPoint) position {
CGSize winSize = [[CCDirector sharedDirector] winSize];
CGRect worldRect = [loader gameWorldSize];
CGPoint centerOfView = ccp(winSize.width/2, winSize.height/2);
int x = MAX(position.x, worldRect.origin.x + winSize.width / 2);
int y = MAX(position.y, worldRect.origin.y + winSize.height / 2);
x = MIN(x, (worldRect.origin.x + worldRect.size.width) - winSize.width / 2);
y = MIN(y, (worldRect.origin.y + worldRect.size.height) - winSize.height/2);
CGPoint actualPosition = ccp(x, y);
CGPoint viewPoint = ccpSub(centerOfView, actualPosition);
self.position = viewPoint;}
我也尝试翻转我使用的角色(LHSprite)
if (newPosition.x< hero.position.x)
hero.flipX=YES;
else
hero.flipX = YES;
但不工作,但我也尝试使用
hero.scaleX=-1
翻转它而不是flipX,翻转但转到屏幕的另一侧翻转。