ippa / jaws

Jaws - HTML5 canvas javascript 2D Game Framework
https://jawsjs.ippa.se
GNU Lesser General Public License v3.0
363 stars 75 forks source link

ParallaxLayer.x and .y don't do anything #64

Closed Manic0892 closed 11 years ago

Manic0892 commented 11 years ago

When ParallaxLayer.x and ParallaxLayer.y are assigned on layer creation, they seem to have no effect on the layer's positioning on the canvas when drawn. Instead, I've had to bruteforce it by adding a constant onto the camera_x and camera_y.

This is based simply on my assumption of how ParallaxLayer.x and ParallaxLayer.y are supposed to act--this may be entirely incorrect. In any case, the only way I could at all affect the layer positioning was by monkeying with line 1931 of jaws.js--setting that to either a constant changed the y positioning of the layer. However, I wasn't sure how the x and y were supposed to be computed, and therefore couldn't figure out how to fix the issue.

ippa commented 11 years ago

ParallaxLayer.x/y isn't (for now) ment to be manipulated directly. You use Parallax.camera_x / camera_y .. and Parallax#draw() will set x/y for all layers according to the damping parameters. Is there a good use-case to manipulate layers x/y directly?

Manic0892 commented 11 years ago

I'm using it in a game with a level width and height of 6400 each. I use a viewport and tethered the Parallax.camera_x and Parallax.camera_y to viewport.x and viewport.y. My expected result when I set ParallaxLayer.y to 6000 was that it would appear at the bottom and that Parallax.camera_y moving would make it appear normal with the viewport centered around the player.

This didn't work--instead, the way I coded it was

this.parallax2.camera_x = this.viewport.x;
this.parallax2.camera_y = this.viewport.y-6000;

This works acceptably and is a good workaround. Therefore, changing the ParallaxLayer.x and .y handling isn't a must, just a convenience that may have been based on my flawed understanding of how it was supposed to work.

Edit: Part of the reason I was confused was that Example 6 sets a ParallaxLayer.y for two different layers. If that's not a valid use case, then the example might need to be fixed.

ippa commented 11 years ago

ok, I'm with you. You're right, it's confusing, i've removed the y-parameters in the example. Later on, one might support both x and y offsets for invidual layers. If you want to make a patch I'll accept it as long as you test it decently. There's some special code for repeating layers and so on to keep your eye on..

ippa commented 11 years ago

I'm closing this since you seem to have a workaround for now.