How do I set spawn locations for my character sprite?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By oliverruehl
:warning: Old Version Published before Godot 3 was released.

Hello,

So basically I need functionality as it is used in many 2D games.

I’d like to create an location/area that my character enters and then gets “beamed” into another spawn location/area.
This can also be useful for scene transitions in games where you can go back and forth.

Thanks a lot guys
Oliver

P.S. Excuse me if I feel lazy, but I’m just starting out with GD Script / Python.

:bust_in_silhouette: Reply From: Calinou

You could place a Node2D whose only purpose is to be used as position to spawn a player. To create the teleport entrance, use an Area2D node and connect its signal to a function that will move the player to the teleport destination (the Node2D’s position).

Also, a Position2D might be preferable to a pure Node2D, as it has a crosshair you can use to place it nicely and accurately but which won’t be visible in the game.

Hinsbart | 2016-05-27 12:41

:bust_in_silhouette: Reply From: puppetmaster-

In our game we use Position2d node as spawnposition.

For spawning enemy randomly on defined points we do it like this

randomize()
spawnPoints = map.get_node("spawnPoints").get_children()

for enemy in enemys:
	var spawnIndex = randi() % spawnPoints.size()
	var spawnPoint = spawnPoints[spawnIndex]
	spawnPoints.remove(spawnIndex)
	var pos = spawnPoint.get_global_pos()
	get_node("game/objects").add_child(enemy)
	enemy.set_global_pos(pos)