This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

how to a add a sprite with code, that takes up area chosen in editor

jackhenjackhen Posts: 11Member

I have a control node and I would to add an area for a sprite to go. The sprite im using is 16x16 pixels, while the area i need it to fill will be much better. How do I choose the size and location of this sprite in the editor, while still being able to actually pick the texture of the sprite from script?

Comments

  • SIsilicon28SIsilicon28 Posts: 693Moderator
    edited April 2020

    Couldn't you simply add the sprite in the editor mode, then change its texture at runtime with code?

  • jackhenjackhen Posts: 11Member
    edited May 2020

    @SIsilicon28 said:
    Couldn't you simply add the sprite in the editor mode, then change its texture at runtime with code?

    no because I need it to be able to have the properties of a control node. The sprite is a 2D node but i need to be able to edit this sprite as if it was a control

  • cyberealitycybereality Posts: 928Moderator

    You can add a sprite with code, but I don't think that really solves your problem. If you're having a problem with the node hierarchy in the editor, doing it in code will not be any easier. You probably have to think about how to arrange the nodes so they are in the formation you need. For example, having a control node and making the sprite a child or something along those lines.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    Additionally, if the sprite is just an image, the TextureRect might work. It extends Control, so you have all of the ability to edit it as needed, but it can also display an image. You can change the texture using something like $TextureRect.texture = load("res://texture_path_here.png").

    Though I agree with @cybereality, in that having a formation for the nodes and how you will need them will help, regardless of whether it is in the editor or through code.

  • jackhenjackhen Posts: 11Member

    Thank you, textureRect was exactly what I needed

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.