Help needed: Simple 'stamping' effect in 2D game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cswjghm

Hey guys, I’m creating a 2D game where a player (represented by a simple colourful circle using AnimatedSprite) WASD moves around the screen. Player can ‘stamp’ anywhere on the screen with Spacebar key, and with every stamp, the player’s circle increases in size. The look of the ‘stamped’ result is retrieved from whatever circle colour/size was displayed.

Problem: I dont know how to create that stamped effect that stays permanently on screen throughout the game (so the screen will be filled with random coloured/sized circles at the end). And how do i retrieve data for colour and size?

Thanks everyone for your help!!

There may be a more eloquent way to do this, but one method would be by creating a copy of the player’s current sprite, and re-parent it to just be another node in the world.

denxi | 2020-02-19 18:54

:bust_in_silhouette: Reply From: newold

You can to create a canvas (A node ColorRect for example fill with transparent). Then you need a variable Array where you save data to stamps (position, color, size…), then attach script to colorRect and use the signal draw() to draw the stamps

In main script:

var StampsArray = []

func add_stamp(position : Vector2, radius : int, color : Color) -> void:
   var data = {
         "position" = position ,
         "radius"    = radius,
         "color"      = color
    }
   # Append data to array of stamps
   StampsArray.append(data)
   # call function in your colorrect
   $colorRect.update_stamps(StampsArray)

in color rect:

var stamps_array = []

func update_stamps(data : Array):
    stamps_array = data
    update() # Force re-draw (function draw() is called)

func draw() -> void:
    for data in stamps_array:
        draw_circle(data.position, data.radius, data.color)