Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by fulvio

I'm in the process of making a platformer (think: Megaman).

I have a few issues with the camera and being able to look ahead as much as possible when either standing close to the left of the screen or running back the other way.

This is the following code I'm using:

this.camera = new Camera(((16 * 16) - ig.system.width), ig.system.height / 3, 5);

What this is doing is placing the character closest to the left side of the screen. This is fine until I turn around and start running back. The character stays there and so does the camera.

What I'm trying to achieve is that the camera moves depending on which side the character is facing and at the same time displays most of the screen. At the moment it's only displaying most of the screen when the character is facing right.

I want to achieve this effect, because most of my enemies might be running around and I won't see them until the very last minute.

Any help would be greatly appreciated.

1 decade ago by paulh

change the camera code when flip : true?

1 decade ago by fulvio

@paulh: Was hoping I wouldn't have to do that.

1 decade ago by dominic

That&039;s <2>, right? It has a #lookAhead.x/y property for precisely this purpose.

this.camera.lookAhead.x = ig.system.width/6;

1 decade ago by fulvio

@dominic: Sure is your camera class! :P I&039;ve played around with #lookAhead.x, however the problem is that when the player is facing the opposite direction -x the camera does not display a look ahead area. Sorry if this doesn&039;t make sense, but I think I need to detect for #this.flip for it to work properly?

Also the following wouldn't work, right?

this.camera.lookAhead.x = ig.system.width/6 : 0;

Following error occurs:

SyntaxError: invalid label
this.camera.lookAhead.x = ig.system.width / 6 : 0;

This is my code at the moment:

this.camera = new Camera(ig.system.width / 3, ig.system.height / 3, 3);
this.camera.trap.size.x = ig.system.width / 6; // please elaborate on these?
this.camera.trap.size.y = ig.system.height / 3;
this.camera.lookAhead.x = ig.system.width / 6 : 0; // causes error above

1 decade ago by dominic

Sorry, edited my code above. Forget about the : 0 - i copied it from the example in the other thread and didn&039;t remove the ternary #?: correctly.

This is the original; it disabled the lookahead on non-mobile systems:
this.camera.lookAhead.x = ig.ua.mobile ? ig.system.width/6 : 0;

1 decade ago by fulvio

Thanks for the reply dom, much appreciated.

Then my player reaches the end of the map (right side). I can still see tiles outside of my main layer. The beginning of the map is fine however. Any ideas?
Page 1 of 1
« first « previous next › last »