17.1 C
New York
Tuesday, April 29, 2025

C ++ – The best way to make a customized GDEXTENSION NODE Draw on the Godot 4.3 editor?


I’m working with Godot 4.3 utilizing Gdextension and C ++. I created a customized class referred to as Participant that inherits from Management. In it _draw() Methodology, I am attempting to attract a easy crimson rectangle. It really works after I run the scene, however after I add the Participant Node to the scene within the editor, nothing seems: the rectangle doesn’t signify within the editor.

Right here is the related code:

// participant.h
#ifndef __BYTENOL_CHESS_PLAYER_H__
#outline __BYTENOL_CHESS_PLAYER_H__

#embrace 

#embrace "piece.h"
#embrace "ChessGrid.h"


namespace godot
{

    class Participant: public Management
    {
        GDCLASS(Participant, Management)

        non-public:
            bool isWhite{ };

        protected:
            static void _bind_methods();

        public:
            Participant();
            ~Participant();
            void _ready() override;
            void _draw() override;


            inline void set_isWhite(bool b);
            inline bool get_isWhite() const;
    };


    inline void Participant::set_isWhite(bool b)
    {
        isWhite = b;
        queue_redraw();
    };

    inline bool Participant::get_isWhite() const
    {
        return isWhite;
    }

}


#endif
// participant.cpp
#embrace "participant.h"

void godot::Participant::_bind_methods()
{
    ClassDB::bind_method(D_METHOD("set_isWhite"), &Participant::set_isWhite);
    ClassDB::bind_method(D_METHOD("get_isWhite"), &Participant::get_isWhite);
    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "isWhite"), "set_isWhite", "get_isWhite");
}

godot::Participant::Participant()
{
    queue_redraw();
}

godot::Participant::~Participant()
{
}

void godot::Participant::_ready()
{
    queue_redraw();
}

void godot::Participant::_draw()
{
    Rect2i rect{ 0, 0, 100, 100 };
    Colour coloration{ 255, 0, 0, 255 };
    draw_rect(rect, coloration);
}

I’ve assured that the .gdexTension file contains device = True:

(configuration)
entry_symbol = "lib_chess_init"
compatibility_minimum = "4.3"
device = true

However the rectangle nonetheless doesn’t signify throughout the graphic window of the editor.

Once I add the Participant Node to the scene within the editor, I need the crimson rectangle to look instantly, because it does in execution time. How do I obtain this? I’ve spent greater than 10 hours looking for an answer.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles