How to flip a Texture2D?

I got a link to the texture. What is the easiest way to flip it on the Y axis?

With scale -1 :slight_smile:

Perhaps it is strange, but I did not find the scale method in the Texture2D class. Could you provide a link to read about it?

PS. The game will run on android native.

Scale is a property on the node itself. If you make it -1 you make a mirror image, aka. flip the image

I know it, thank you. I do this by using a texture and creating a custom canvas, then scale it like this. In the end, all I want is the inverted texture itself. If I use a node for this, the node will be reversed, but the texture itself will still be the same as it was, or not?

Hmm okay, I understand, but I don’t understand the use-case for this. Yes the texture will still be the same but the node would flip the texture which is part of the node. Isn’t that good enough?

If you don’t want to “flip” the node then the only way I can think of is to create a shader material that “flips” the image.

My ultimate goal was (I have already changed the logic of the game) to get the color of the image pixel by the coordinates of the cursor on the screen. A photo is displayed on the screen, and there is a “mask” image that is not displayed. When the cursor moves across the screen over a photo, a pixel is read from the “mask” according to its coordinates, in which information about what is currently displayed under the cursor. This information is passed to the photo shader, and depending on it, the desired area of ​​the photo is either highlighted or not.

The “mask” is also used to get data by coordinates, and it is also used as the second texture of the highlighted areas in the photo shader. Resizing the window does not affect the display.

I’ve implemented everything, but I’m only using a custom canvas. This is no longer a cross-platform solution. The canvas needed an inverted texture. Here the question arose whether it is possible to turn it over in CC, or it is also possible to do this only using the canvas settings.

Whatever the case, thanks for the help.

chrome_PkaF4VIa9d

Interesting and looks cool! Have you tried CSS

transform: scaleX(-1);

This would flip the whole canvas. Just make sure to flip some top HTML element of what Cocos requires, otherwise you might break the click/hover areas.

What version is used?Is that what you need?
spriteComponent:
2.x:
cc.find('Canvas/HelloWorld').getComponent(cc.Sprite).spriteFrame.setFlipY(true) cc.find('Canvas/HelloWorld').getComponent(cc.Sprite).setVertsDirty()

3.x:

find('Canvas/Sprite').getComponent(Sprite).spriteFrame.flipUVY = true
find('Canvas/Sprite').getComponent(Sprite)._updateUVs()

I am using version 3.5.0.

Strangely. When I try to call the _updateUVs() method, I get “Property ‘_updateUVs’ does not exist on type ‘Sprite’.” :thinking:

In any case, if after that I can get a texture from this sprite, and the texture will be flipped without sprite settings, yes, it would be a solution to the issue.