How to spawn coins?

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

Currently my code could continuously spawn a node(coin) after a time period.
But I need to spawn multiple coins(multiple instance of the same node) at a time at consecutive x positions and const y position(that is spawning 1 to 5 coins at a time),please give me a sample code or steps to do that.
I hope that my question is clear :slight_smile:
Thank you.

If you already know how to spawn a single coin on a timer, you’re mostly there. You just need to spawn multiple coins (likely in a simple loop) instead of just one, and position them at your fixed positions. What part of that are you having trouble with?

jgodfrey | 2022-10-13 21:59

Thank you for your comment,but I don’t know how to spawn multiple coins instead of one

Krizz | 2022-10-14 08:15

Currently my code could continuously spawn a node(coin) after a time period.

What does your coin spawning code look like now?

jgodfrey | 2022-10-14 16:16

:bust_in_silhouette: Reply From: alexp

Suppose you keep the code to spawn one coin in spawn_coin(x, y). Then you can spawn more with

func spawn_coins(x: float, y: float, num_coins: int, spacing_x: float):
  for i in range(num_coins):
    spawn_coin(x + i * spacing_x, y)