-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In WEBGL renderer, the mask on a group does not work if group.getBounds() is invoked #334
Comments
I found a couple ways to fix this. I'm not sure why they work, but here's my guess. If you add In the example the mask is created with So the better fix is changing I don't think this is a bug. Masks just aren't meant to go on the display list. |
It works, thanks, @jbpuryear |
Didn't notice that, thanks. |
So I have a mask which I want to position at the same place as a sprite. I call the following:
and it works fine, until anywhere else in code calls I think it's the same issue as expressed here. Given that (correct me if I'm wrong), anything I want to display on the screen is going to be a child of the stage, and calling Any ideas? Thanks! Update: My workaround for this was the following:
to the following:
as it appears that |
It looks like masks are supposed to be in the display list, probably in If you have to use Stage#getBounds(), I guess you could mark the mask dirty each time. I'd guess the
block is never run because AFAIK Phaser never marks masks as non-renderable. @griever989 I opened sprites/mask and ran |
I am encountering a version of this issue myself (with webgl of course) I have a complicated animated sequence, with a lot of animation going on relating to group scale / width / height properties. Amongst this, is a group containing a mask. As the masked group is positioned dynamically (and we often want to animate it and move it around), using the display list as a simple way to scale the mask (as part of the group that it is masking) makes sense (we are making slot games, and also animating the content within the masked area). The confusing thing is, it seems to be nothing to do with any scaling of the masked group (which also contains the mask) that breaks masking for webgl: its all the other content being rendered. When i remove all calls to setting scale, reading or writing to width / height properties, the mask started to work again. Its making it hard for me to find a working solution, as i have not yet been able to simplify my example down to a single line of code that would make it work / not work. If this isn't classified as a bug, then the implication is you cannot use masks in phaser (or maybe pixi?) very flexibly, ie: you aren't able to add them as part of a group which is scaled or moved (not if you want to use webgl - it works fine for canvas, which adds to the confusion). This is a shame: its not clear to me from the documentation that this would be the case, and its different to every other display list library I have used. I also didn't find anything in the documentation (yet?) which explained whether i should or should not be adding masks manually to the display list. (the Phaser examples for masking are quite simple use cases). So i think both the documentation and examples could be much clearer about what are the supported uses of masks in Phaser. |
I would favor making the change in #334 (comment) for v2.11.0 (https://codepen.io/samme/pen/aGoKpK). It may change the effects of some existing code, since masks will no longer be included in bounds calculations. Oddly, @Robominister did you try setting |
@samme We were trying to add tweens of the scale (or width / height) properties on the masked object, so if doing that, it looks like we might have to set dirty manually in an update function (as in your example) ? (Although we are using TimelineMax, i dont know off the top of my head if it actually reads the properties that it is tweening on an object during the tweens update). |
This Issue is about A bug in the API PIXI.DisplayObjectContainer.prototype.getBounds()
In Phaser.WEBGL renderer, the mask on a group does not work if group.getBounds() invoked
but it still works if you use Phaser.CANVAS renderer
please see online example:
https://phaser.io/sandbox/edit/ogYiKNXF
FYI: This issue is found when I try to use alignIn() to align a group with a mask inside, but the mask does not work. (because the method alignIn() invokes the getBounds() )
The text was updated successfully, but these errors were encountered: