start button highlights like i’m pressing it, but nothing happens. what am i doing wrong, 3rd time through really thought it would work… when i run it game is playing my character is in its upper left start point so that is the first thing i i have to fix, i can move and disapear when hit but the HUD is up the whole time start button not working, doesn’t work after i die either
We can’t help you without seeing any of your code, scene structure and screenshots. Can you provide these please?
Make sure to use preformatted text with ``` for code snippets.
extends Node
@export var mob_scene: PackedScene
var score
func game_over() -> void:
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()
func new_game():
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()
$HUD.update_score(score)
$HUD.show_message("Get Ready")
func _on_score_timer_timeout():
$HUD.update_score(score)
score += 1
func _on_start_timer_timeout():
$MobTimer.start()
$ScoreTimer.start()
func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()
# Choose a random location on Path2D.
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()
# Set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location.rotation + PI / 2
# Set the mob's position to a random location.
mob.position = mob_spawn_location.position
# Add some randomness to the direction.
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
# Choose the velocity for the mob.
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
# Spawn the mob by adding it to the Main scene.
add_child(mob)
extends Area2D
signal hit
@export var speed = 400 # How fast the player will move (pixels/sec).
var screen_size # Size of the game window.
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
var velocity = Vector2.ZERO # The player's movement vector.
if Input.is_action_pressed("move_right"):
velocity.x += 1
if Input.is_action_pressed("move_left"):
velocity.x -= 1
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
$AnimatedSprite2D.play()
position += velocity * delta
position = position.clamp(Vector2.ZERO, screen_size)
else:
$AnimatedSprite2D.stop()
if velocity.x != 0:
$AnimatedSprite2D.animation = "walk"
$AnimatedSprite2D.flip_v = false
# See the note below about the following boolean assignment.
$AnimatedSprite2D.flip_h = velocity.x < 0
elif velocity.y != 0:
$AnimatedSprite2D.animation = "up"
$AnimatedSprite2D.flip_v = velocity.y > 0
func _on_body_entered(body) :
hide() # Player disappears after being hit.
hit.emit()
# Must be deferred as we can't change physics properties on a physics callback.
$CollisionShape2D.set_deferred("disabled", true)
func start(pos):
position = pos
show()
$CollisionShape2D.disabled = false
extends CanvasLayer
# Notifies `Main` node that the button has been pressed
signal start_game
func show_message(text):
$Message.text = text
$Message.show()
$MessageTimer.start()
func show_game_over():
show_message("Game Over")
# Wait until the MessageTimer has counted down.
await $MessageTimer.timeout
$Message.text = "Dodge the Creeps!"
$Message.show()
# Make a one-shot timer and wait for it to finish.
await get_tree().create_timer(1.0).timeout
$StartButton.show()
func update_score(score):
$ScoreLabel.text = str(score)
func _on_start_button_pressed():
$StartButton.hide()
start_game.emit()
func _on_message_timer_timeout():
$Message.hide()
Please make sure you format your code properly, because it is super hard to read in the current state. Here’s a good explanation how to do that:
What I managed to notice is that you are emitting your start_game signal, but you don’t connect to it anywhere. That’s why clicking the button doesn’t do anything. Also make sure to connect the button’s pressed signal to the _on_start_button_pressed method, as I think you haven’t done that either.
you should find it acceptable now, thank you for the help posting!! ok so i need to figure out how to attach that signal to the button, but why does it start with the game running and HUD up!?
If you want the game to start paused, you need to explicitly pause it at the start of the game, e.g. with get_tree().paused = true line in one of your _ready() functions, ideally in some GameManager script that would manager the game’s state.
HUD is shown because you added it to the main scene, why would you expect it to not be shown?
touche on the HUD, doing a signals lesson now to get that button fixed. so you know the sprite2D icon guy they make in that first lesson that you can move around, i’m trying to move him into my game as a second character that can be played simultaneously with the main eyeball character…?? but when i put that guy into a new scene and connect it to the main and add the script the same it shows the icon but i cant move it… any ideas?