1

我正在使用 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,翻转但转到屏幕的另一侧翻转。

4

1 回答 1

0

部分解决。

似乎

myParallax = [loader parallaxNodeWithUniqueName:@"Parallax_1"];

搞砸了,所以我禁用它,

我将第一种方法更改为

-(void)applyJoystick:(SneakyJoystick *)aJoystick forTimeDelta:(float)delta{
CGRect worldRect = [loader gameWorldSize];
CGSize winSize = [[CCDirector sharedDirector] winSize];
CGPoint scaledVelocity=ccpMult(aJoystick.velocity, 200.0f);
CGPoint newPosition =ccp(hero.position.x+scaledVelocity.x*delta, hero.position.y +scaledVelocity.y *delta);

float posX = MIN(worldRect.size.width - hero.centerToSides, MAX(hero.centerToSides, newPosition.x));
float posY = MIN(winSize.height -winSize.height/2+ hero.centerToBottom, MAX(hero.centerToBottom, newPosition.y));

if (scaledVelocity.x >= 0)
    hero.scaleX = 1.0;
else
    hero.scaleX = -1.0;

[hero setPosition:ccp(posX, posY)];
}

似乎当滚动不正确并进入世界之外的白色区域并且一切都正确时,您需要找到一个关于视差比、水平大小和速度的方程。

于 2012-11-13T10:28:12.817 回答