0

hello I'm making a super pong game that has a power up that adds another ball to the game. The next ball should appear in the center of the screen.

  extends Node2D

var collect = false


func _physics_process(delta):
    $Area2D/AnimatedSprite.play("Spin")



func _on_Area2D_body_entered(body):
    print(body.name)
    if body.name=="Ball"&&collect==false:
        collect = true
        $Collection.play()
        $AnimationPlayer.play("Fade")
        $Area2D/AnimatedSprite.stop()
        var ball =  load("res://ball/Ball.tscn").instance()
        ball.global_position = Vector2(0,0)

the orb plays the animation and sounds but the ball doesn't load into the game.

Godot version 3.2.3

2 Answers2

0

I managed to come up with a solution but if anyone has any better suggestions I am open to it.

extends Node2D

var collect = false
var ballscene = null

func _physics_process(delta):
    $Area2D/AnimatedSprite.play("Spin")



func _on_Area2D_body_entered(body):
    print(body.name)
    if body.name=="Ball"&&collect==false:
        collect = true
        $Collection.play()
        $AnimationPlayer.play("Fade")
        $Area2D/AnimatedSprite.stop()
        var ball =  load("res://ball/Ball.tscn")
        ballscene = ball.instance()
        find_parent('SpawnManager').add_child(ballscene)
        
        
0

I see that you reach a answer to your problem, i will share the code that i managed to use a "spawner" in one of my games:

extends Node2D

export(PackedScene) var to_be_spawned 
export(int) var amount

func _ready():
    pass
func _process(delta):
    pass

func spawn_this():
    
    # _N is just to count, not used
    for _N in range(amount):
        
        var nut
        nut = to_be_spawned.instance()

        nut.position = self.position
        nut.scale = self.scale
        
        get_parent().add_child(nut)

You need to select the Scene you want to spawn in "to_be_Spawned", any scene, I recomend don't spawn the Initial-Menu for exemple XD After this I instance the Node where I want and Animate like Particles.

The AnimationPlayer inside the Spawner to call the function spawn_this