How to give a color to Area2D

Vale-gitVale-git Posts: 171Member

Hi, it is possible to give a background color / border color to and Area2D?
If yes someone can give me the steps I need to accomplish that please? - in the simplest way possible -

Thank you

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 4,292Admin

    1: Create a image that’s just a white square
    2: Assign that image to a sprite and make it the child of the area2D
    3: Scale the sprite to fit the area2D’s collision shape
    4: (Optional) change the color of the sprite using modulate in the materials field to get different colored backgrounds

    The advantage of doing it like this though is if you scale the area2D, the sprite still fits. The disadvantage is that it only works for square and rectangle area2Ds.

    That’s how I would do it, but there’s probably better/simpler ways to go about it :sweat_smile:.

  • NeoDNeoD Posts: 202Member
    edited December 2017

    I agree with the post above but you can also draw a polygon. Here's the Godot 2.1 method.
    http://docs.godotengine.org/en/stable/classes/class_canvasitem.html#class-canvasitem-draw-polygon

    You can fetch your Area points coordinates using get_shape(0).get_points() to feed the draw_polygon method.

  • Vale-gitVale-git Posts: 171Member

    How about to use existent border? With some refactor it will be easy to set on all the time - or with an option box -.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file