phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.16k stars 7.1k forks source link

Textures should have a way to `erase` a portion of the texture via a size / width / height #6853

Closed SelfDevTV closed 4 months ago

SelfDevTV commented 4 months ago

The problem

I have a dynamic texture I draw 1000s of numbers on it (via Phaser.Gameobjects.Text or BitmapText) and via tex.draw(). Sometimes I want to remove the text from a specific location on the texture. The only way I found this was via .erase. Problem is it only takes in a Gameobject but not the size itself. When i give it my text gameobject it will remove it but in a very weird way. Here is a screenshot:

image

A fellow discord mate helped me out with a workaround:

const rect = this.add.rectangle(0, 0, 10, 10, 0);
dynTexture.erase(rect, 0, 0);

But still I thought why not implement another way of this function, that will also take in a size or width + height parameter. I would also like to try to implement it.

API for example for a DynamicTexture might look like this: dynTexture.erase(width: number, height: number = width, x: ....)

[Optional] Do you want to help provide this feature? Yes. API for example for a DynamicTexture might look like this: dynTexture.erase(width: number, height: number = width, x: ....)

rexrainbow commented 4 months ago

How about clearRect method name, similar as clearRect in canvas api

SelfDevTV commented 4 months ago

Yes that could work too. Infact i was searching for this method at first, but then found it's called erase. @rexrainbow do you know how that normally works? Should I just create a fork go ahead and send a PR or do we talk about it first / have to get assigned first. etc? Sorry would be my first contribution kinda

photonstorm commented 4 months ago

clear already exists - it would be easier to just allow you to pass 4 optional parameters to it, rather than increase the API size.

erase is not the same thing, that uses a special blend mode and the pixels from the textures to remove it, and then you have to factor in alpha blending on non-opaque pixels too. It's meant more as a way to punch a 'shape' into a dynamic texture, than to clear an area.

SelfDevTV commented 4 months ago

clear already exists - it would be easier to just allow you to pass 4 optional parameters to it, rather than increase the API size.

Yes that would be the best way I think. It should take 4 optional parameters ala x: number, y: number, width: number, height: number = width or something like that.

erase is not the same thing, that uses a special blend mode and the pixels from the textures to remove it, and then you have to factor in alpha blending on non-opaque pixels too. It's meant more as a way to punch a 'shape' into a dynamic texture, than to clear an area.

Ok understood now :) thx for clarifying

cy920820 commented 4 months ago

The problem

I have a dynamic texture I draw 1000s of numbers on it (via Phaser.Gameobjects.Text or BitmapText) and via tex.draw(). Sometimes I want to remove the text from a specific location on the texture. The only way I found this was via .erase. Problem is it only takes in a Gameobject but not the size itself. When i give it my text gameobject it will remove it but in a very weird way. Here is a screenshot:

image

A fellow discord mate helped me out with a workaround:

const rect = this.add.rectangle(0, 0, 10, 10, 0);
dynTexture.erase(rect, 0, 0);

But still I thought why not implement another way of this function, that will also take in a size or width + height parameter. I would also like to try to implement it.

API for example for a DynamicTexture might look like this: dynTexture.erase(width: number, height: number = width, x: ....)

[Optional] Do you want to help provide this feature? Yes. API for example for a DynamicTexture might look like this: dynTexture.erase(width: number, height: number = width, x: ....)

Are you running full screen on a mobile device? The font is so blurry

SelfDevTV commented 4 months ago

Just zoomed in by a lot with the main cam. Maybe that's why

zekeatchan commented 4 months ago

Hi @SelfDevTV, thanks for submitting this feature request.

We have implemented the feature that will allow you to clear a specified area of a dynamic texture like so: dynamicTexture.clear(x, y, width, height)

This update has been pushed to the master branch and will be part of the next release. Do test it out and feel free to reach out if you need further assistance.

SelfDevTV commented 4 months ago

Hi @SelfDevTV, thanks for submitting this feature request.

We have implemented the feature that will allow you to clear a specified area of a dynamic texture like so: dynamicTexture.clear(x, y, width, height)

This update has been pushed to the master branch and will be part of the next release. Do test it out and feel free to reach out if you need further assistance.

OMG you guys are awesome. Keep it up :) Thank you very much!