Pixelmask, Camera, and scrollX / Y


(Wayne Makoto Sturdy) #1

So, I’ve noticed that the Pixelmask of an Entity does not stay aligned with the graphic when the graphic’s scrollX and/or scrollY properties are set to something other than 1 and the camera point is something other than 0, 0.

I’ve found that I can override the update or render functions of the Entity and move the mask’s position via:

Pixelmask(mask).x = FP.camera.x - _maskOffset.x - (FP.camera.x * Image(graphic).scrollX);
Pixelmask(mask).y = FP.camera.y - _maskOffset.y - (FP.camera.y * Image(graphic).scrollY);

I’ve noticed that the mask lags behind the graphic (probably because this Entity updates before the camera) and this could be a problem for fast moving entities.

One alternative I entertained, but quickly dispatched with, was to not use the scrollX and scrollY properties, but rather re-position the Entity itself. This method could cause visible lag of the Entity’s graphic and not just the Pixelmask.

I was wondering if anyone had some insight on this or if there is a better way to position the mask using a different method.


(Abel Toy) #2

Yeah, that’s the expected behaviour.

How do you update the camera? Maybe calling the code before the super.update(); line in your World's update function would solve this.


(Wayne Makoto Sturdy) #3

I’m working in a basic test environment so my camera code is in the World’s update override at the moment, and yeah, I tried calling super.update() after the camera block instead of before, but I still get the same result.

I guess its not a big problem all in all since the error margin is minuscule, but I guess I was just hoping there was an easy and logical fix.

If the scroll values are set to zero, effectively making the graphic static/camera independent, I see no lag however.

The reason I’m eager to solve this is that I am creating an extension of Entity that will serve as a base class for any Entity needing pixel perfect collision detection. This class already handles the redraw of the Pixelmask on rotation of the graphic as well as the option of redraw on every frame in the case of the graphic being an animated spritemap, and am currently working on getting it to handle a Graphiclist.


(Alex Larioza) #4

This has been a long known issue with FlashPunk, but the masks aren’t actually lagging behind. Its only the drawing of the box/mask that is lagging and does not effect actual collisions.


(Wayne Makoto Sturdy) #5

good to know!

I miss being able to search through the old forums, lots of information there… I guess we rebuild.