1

I am making a side scrolling game with levelhelper and sneakyinput. i have couple questions. i have sneakyinput on a different layer and i am facing a problem on scrolling with the parallax at 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

  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.

Haris
  • 129
  • 1
  • 9

1 Answers1

0

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.

Haris
  • 129
  • 1
  • 9