简体   繁体   English

使用levelhelper在cocos2d中进行侧滚动边界

[英]side scrollling boundaries in cocos2d with levelhelper

I am making a side scrolling game with levelhelper and sneakyinput. 我正在用levelhelper和slipneyinput制作侧面滚动游戏。 i have couple questions. 我有几个问题。 i have sneakyinput on a different layer and i am facing a problem on scrolling with the parallax at levelhelper. 我在不同的层上有sneggyinput,并且在levelhelper上使用视差滚动时遇到了问题。

i cant manage to apply boundaries and move the layer properly. 我无法应用边界并正确移动图层。 how i will fix the scrolling? 我将如何解决滚动问题? to be inside the boundaries and the character centered? 在边界内并且角色居中吗?

i have those 2 methods inside the update method 我在更新方法中有这两种方法

  -(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;}

also i try to flip the character (LHSprite) i use 我也尝试翻转我使用的字符(LHSprite)

  if (newPosition.x< hero.position.x)
    hero.flipX=YES;
else
    hero.flipX = YES;

but isnt working but i tried to use also 但不能正常工作,但我也尝试使用

   hero.scaleX=-1 

to flip it instead of flipX,flips but goes to the other side of the screen fliped. 将其翻转而不是flipX,但会翻转但翻转到屏幕的另一侧。

solved partially. 部分解决。

it seemed that 似乎

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

was messing it up so i disable it, 搞砸了,所以我禁用它,

i change the first method to 我将第一种方法更改为

-(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)];
}

it seems when the scrolling isnt correct and goes to white area out of the world and everything is correct you need to find an equation about parallax ratio and levelsize and velocity. 似乎,当滚动不正确并且进入世界的空白区域并且一切都正确时,您需要找到一个关于视差比,水平和速度的方程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM