good afternoon. In the examples, there is such a mini-game, scratch.:
https://phaser.io/examples/v3/view/game-objects/render-texture/scratch
Here, type: Phaser.Webgl is set in config. Is it possible to make the same game, but on Canvas?
good afternoon. In the examples, there is such a mini-game, scratch.:
https://phaser.io/examples/v3/view/game-objects/render-texture/scratch
Here, type: Phaser.Webgl is set in config. Is it possible to make the same game, but on Canvas?
Thank you
I have an additional question: how can I determine that the top layer is completely erased (scratched) (or a certain part of it: 50%, 70%, 90%)? How do I detect that the player has erased the top layer and show it a picture or perform another action?
The codePen example does this:
handlePercentage(getFilledInPixels(32));
It basically checks every pixel, so for performance reasons it âstridesâ.
I need some help as there are issues with both options at the moment. In the first case, if I use RenderTexture, the browser breaks: the screen is black, there is nothing in the console (and no errors), no button works, you canât refresh the page (only restarting the browser helps). At the same time, the example on the first link works correctly in the browser.
What about the second example (links): do I understand correctly that Phaser supports all the tools that are available in the standard canvas as well? That is, you can integrate the code from the second link into the classes using the Phaser methods?
The first example doesnât use a RenderTexture.
Both examples use a standard Canvas, so yes, Phaser supports exactly the same.
You can basically use the codePen example as is.
Maybe put your breaking code online somewhere.
Iâm sorry, I made a mistake with the first link - I meant it:
https://labs.phaser.io/edit.html?src=src/game%20objects/render%20texture/erase%20part%20of%20render%20texture%20canvas.js&v=3.54.0#
Works for me.
To count pixels on a RenderTexture you would have to draw it on a CanvasTexture, so I think youâre better of just using a CanvasTexture.
First of all, I want to thank you again for your help.
If you donât mind, letâs start from the beginning and in order. I need to create the following mini-game using Phaser 3. Starting data:
The gameplay is as follows: when the player draws on the shadow of the character, the real image of the hero appears in this place, which is under the shadow (the player seems to erase the image).
When the shadow is completely erased (or most of it), a greeting pops up
How should I start? Thank you very much for any help
Upd. If I want to integrate the code from the example at the 2nd link (codepen), then I should use this - Phaser 3 API Documentation - Class: CanvasTexture. Am I right?
Yes. The first link (from the solution) already does this. You can just use that example.
Add the background to the scene.
Add your character to the scene.
Now create a CanvasTexture.
Draw your shadow on the canvas.
Add the canvas to the scene.
Now if you draw with the brush, the shadow will disappear.
this.background = this.add.image(0, 0, âbackgroundâ);
this.womanOwl = this.add.image(0, 0, âheroowlâ);
const canvasText = this.textures.createCanvas(âcanvastextureâ, 800, 600);
I started with this on my Scene. But an error appeared in the console: âTexture key already in use: canvastextureâ. I didnât use âcanvastextureâ anywhere else in the code
That doesnât make sense
Create a CodePen, and login on Discord, then I can guide you through.
I have solved the problem with creating a canvas Texture, however this is just the beginning of my problems)) I created a codepen example on phaser 3 (copied the basis of another project):
I added a canvas Texture, created an image from base64 (as in the example on codepen) and am trying to draw this image. But nothing is displayed. I suppose the problem is exactly how I add the image, right?
Fork this example:
It works! That is, I only needed to add the created canvas texture to the scene as an image (this.add.image)? Thank you very much!
UPD. And what it is necessary for this:
this. add. image(0, 0, âcanvastextureâ). setOrigin(0)
I know how setOrigin works, but here for some reason it has a different logic than the one Iâm used to
If you donât mind, weâll continue. Now I need to make the image interactive. I canât hang the addEventListener (addListener) on the canvas Texture that the block is drawn with, right? So I need to add interactivity to the block image itself? So that I can erase it and develop the image underneath it (which will be added later), right?
A forum doesnât lend itself for quick back and forth.
Please continue on https://discord.gg/phaser