0 votes

Hi all, I had a little question I've been thinking over for a day now.

In my game, I have the main scene. in it, I'm instancing a Particles2D, and I want to be able to toggle it on and off with the signals emitted for pressing the "Play" button, and when an enemy enters a certain area.


extends Node2D

const SCREEN_HEIGHT = 580
const SCREEN_WIDTH = 1010

signal game_over

var timescore
var kills
var finalscore
var EnergyShot = preload ('res://player-side/EnergyShot.tscn')
var eyeworm = preload ('res://Enemy.tscn')
var SpawnWaitTime = 5
var highscore = 0.0

func _ready():

func _on_SpawnTimer_timeout():
    var enemy = eyeworm.instance()
    enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
    enemy.connect("kill", self, "_on_kill")
    SpawnWaitTime -= 0.15
    if (SpawnWaitTime < 0.4):
        SpawnWaitTime += 4.85

func _on_SurvivalTimer_timeout():
    timescore += 1

func _on_kill():
    kills += 1

func _on_BaseArea_area_entered(area):
    finalscore = timescore + kills*5
    if highscore < finalscore:
        highscore = finalscore
    $HUD.player_loss(finalscore, highscore)
    $BaseArea/CollisionShape2D.disabled = true
    get_tree().call_group("EyeWorms", "queue_free")

func _on_HUD_play_game():
    timescore = 0
    kills = 0
    SpawnWaitTime = 5
    finalscore = 0
    $BaseArea/CollisionShape2D.disabled = false

func _on_HUD_credits():


extends CanvasLayer

signal play_game
signal credits

func show_message(text):
    $SystemMessage.text = text

func _on_MessageDuration_timeout():

func player_loss(finalscore, highscore):
    show_message("Game Over")
    yield($MessageDuration, "timeout")
    $SystemMessage.text = "Play Again?"
    $HighScore.text = str(highscore)
    $CurrentScore.text = str(finalscore)

func score_count(score):
    $TimeSurvived.text = str(score)

func kill_count(count):
    $Kills.text = str(count)

func _on_Button_pressed():
    $TimeSurvived.text = str("0")
    $Kills.text = str("0")

func _on_HelpButton_pressed():
    yield($Help/ShowHelpDuration, "timeout")

func _on_CreditsButton_pressed():

func _on_HUD_credits():

Thruster.gd (This is the Particles2D node)

extends Particles2D

var playing = false
in Engine by (198 points)

1 Answer

0 votes

First of all your Thruster.gd should look like this if you want it to not have autoplay when beign instanced.

 extends Particles2D

    emitting = false
    one_shot = true # false if you want it to loop

Then signals to your button and area nodes.

func _on_Area2D_body_entered(body):
        get_node("Thuster").emitting = true

func _on_Button_pressed():
       get_node("Thuster").emitting = true
by (102 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.