0 votes

Hi as in title i would to know how can i set on sprite pixels using c# script. I tried before change pixel on sprite using script but this didn't work in my project under i give a part of script


    Sprite map = GetNode("/root/Node2D/Sprite") as Sprite;
    var image = map.GetTexture().GetData();

    for (int w = 0; w <= map.GetTexture().GetWidth(); w++)
        for (int h = 0; h <= map.GetTexture().GetHeight() ; h++)
            image.SetPixel(w, h, Color.Color8(244, 253, 21, 50));

in Engine by (74 points)
edited by

What is not working? This code might successfully modify the pixels you downloaded from the graphics card, but it won't upload them back (unless you did it later in your code?)

so if you could me tell how can i upload my received pixel back?

1 Answer

+1 vote
Best answer

If your sprite has initially a StreamTexture on it, you will have to create another one of type ImageTexture.

var tex = new ImageTexture()
tex.CreateFromImage(image, map.GetTexture().Flags)

Note: in your code you are filling the whole texture with the same color, you could use Fill instead.

by (28,744 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.