Aligning added background with Y parallax is confusing me


(Jean) #21

But the Tilemap must be the graphic of an entity, use the code where the entity that receives the Tilemap as the graphic.

Also, the 1f thing is to “force” saying “hey compiler, I know that you want to make this number 1 a integer, but make it a Float(like the Number from ActionScript) OK?”. That kind of thing is necessary on Java and other C derived languages, otherwise the result could be an integer and then the scrollY would always result in 0, but don’t worry about that, first world language problems :wink:


(Jacob Albano) #22

Ah yes, the 1f is a holdover from C# that I missed when I replaced it.

So this should just be the entity that your tilemap is attached to. When you add the graphic:

addGraphic(_map_BG, 2, 0, -(122));

change that to be two calls where you set the image position afterwards:

var bgEntity:Entity = addGraphic(_map_BG, 2);
setRenderY(_map_BG, 100, camera, bgEntity);

That should hopefully work. If you don’t want to move the entity at all, don’t even bother passing it and it should have the same effect.


(John Andersson) #23

Okay thanks. I tried it but the background layer is still off. It’s too far down. May I ask, why the number 100? I changed it do 0 and now the background layer is aligned good when the camera’s Y value is at 0 (which is still not what I want).

I want the bottom (the pixel furthest down) of the background layer to be visible when the camera is at its highest Y value (which changes depending on the level).

Such a tricky mind****ing problem


(Jacob Albano) #24

100 doesn’t matter, it’s just a test number I put in. Ultimately, that value you pass it is the position that the image will appear as though it had no scrolling. This problem you’re describing is slightly different to what I thought originally. How are you determining your scrollY value? That might be something you want to calculate based on the height of the image and the max y position of the camera.

Doing this:

setRenderY(_map_BG, maxCameraHeight, camera);

will put it in the right position while accounting for scrolling, but I feel like that’s not actually the solution you’re looking for after all.


(John Andersson) #25

Hmmm… this is confusing, I made another drawing which should explain the problem better?


(Zachary Lewis) #26

It sounds like you don’t actually need any Y-parallax. You could probably just set the scrollX property and just set the Y location to the desired position.


(John Andersson) #27

I don’t really need it, but I want it! It looks so much better when the background scrolls slowly if you move upward