extends Sprite
var speed = 80
var velocity = Vector2()
var stun = false
var hp = 3
var blood_particles = preload("res://Blood_Particles.tscn")
onready var explode_sound = $Explode
func _process(delta):
if Global.player != null and !stun:
velocity = global_position.direction_to(Global.player.global_position)
elif stun:
velocity = lerp(velocity, Vector2(0, 0), 0.3)
global_position += velocity * speed * delta
if hp <= 0:
Global.points += 10
if Global.node_creation_parent != null:
var blood_particles_instance = Global.instance_node(blood_particles, global_position, Global.node_creation_parent)
blood_particles_instance.rotation = velocity.angle()
if explode_sound:
explode_sound.play()
queue_free()
func _on_Hitbox_area_entered(area):
if area.is_in_group("Enemy_damager") and !stun:
modulate = Color.white
velocity = -velocity * 6
hp -= 1
stun = true
$Stun_Timer.start()
area.get_parent().queue_free()
func _on_Stun_Timer_timeout():
modulate = Color("ff4848")
stun = false
#WHY
69 messages · Page 1 of 1 (latest)
did you make a thing which stops it from restarting constantly?
wdym?
like
lets say you want to play a jump sound
if you are not touching the ground the sound plays, but it keeps trying to play the same audio again and again while youre in the air
something like that
As an explanation of what's (likely) happening, any code you put in process will run every frame (60 times a second). The way it's set up it's running the code to start the audioplayer every frame.
if it keeps repeating the first few miliseconds its hard to hear
You won't hear it. An audiostreamplayer has a single track, and that track is being restarted every 1/60th of a second
coudl be the case
;0
So it's playing, it's just playing the first 1/60th of the file over and over, basically
maybe try something like this
maybe a score_changed signal?
The easy way is to wrap the method call to start the player in an if statement that checks if it's already playing.
explode_player.play()```
Don't copy/paste, the indenting is all wrong. I'm on phone.
if hp <= 0:
Global.points += 10
if Global.node_creation_parent != null:
var blood_particles_instance = Global.instance_node(blood_particles, global_position, Global.node_creation_parent)
blood_particles_instance.rotation = velocity.angle()
if explode_sound && !explode_sound.playing:
explode_sound.play()
queue_free()
well if I do that
Invalid get index 'is_stopped' (on base: 'AudioStreamPlayer').
this happen :<
Oh, I think it's a method, not a var. Try adding parentheses to the end of is_stopped()
(Sorry. At work)
It should call the method is_stopped() on the audioplayer and return true or false for the if to evaluate
Try if explode_sound && explode_sound.is_stopped():
if hp <= 0:
Global.points += 10
if Global.node_creation_parent != null:
var blood_particles_instance = Global.instance_node(blood_particles, global_position, Global.node_creation_parent)
blood_particles_instance.rotation = velocity.angle()
if explode_sound && explode_sound.is_stopped():
explode_sound.play()
queue_free()
Invalid call. Nonexistent function 'is_stopped' in base 'AudioStreamPlayer'.
this still happens 🥲
or is it a signal
oh right
is_stopped is 3.x, my bad
I feel so dumb, as I just used the is_stopped functionality on my own project in 3.5 this morning
Eh, it's something obvious that'll make us kick ourselves when we solve it. That's dev 🙂
When you tried is_stopped did you try it with and without parentheses? I swear one of those should work.
if hp <= 0:
Global.points += 10
if Global.node_creation_parent != null:
var blood_particles_instance = Global.instance_node(blood_particles, global_position, Global.node_creation_parent)
blood_particles_instance.rotation = velocity.angle()
if explode_sound && explode_sound.is_stopped:
explode_sound.play()
like this?
Invalid get index 'is_stopped' (on base: 'AudioStreamPlayer').
this happens still :(
Hm. I'm probably missing something very obvious.
extends Sprite
var speed = 80
var velocity = Vector2()
var stun = false
var hp = 3
var explode_sound_instances = []
var blood_particles = preload("res://Blood_Particles.tscn")
onready var explode_sound = $Explode
func _process(delta):
if Global.player != null and !stun:
velocity = global_position.direction_to(Global.player.global_position)
elif stun:
velocity = lerp(velocity, Vector2(0, 0), 0.3)
global_position += velocity * speed * delta
if hp <= 0:
Global.points += 10
if Global.node_creation_parent != null:
var blood_particles_instance = Global.instance_node(blood_particles, global_position, Global.node_creation_parent)
blood_particles_instance.rotation = velocity.angle()
var sound_instance = explode_sound.play()
if sound_instance != null:
explode_sound_instances.append(sound_instance)
queue_free()
func _on_Hitbox_area_entered(area):
if area.is_in_group("Enemy_damager") and !stun:
modulate = Color.white
velocity = -velocity * 6
hp -= 1
stun = true
$Stun_Timer.start()
area.get_parent().queue_free()
func _on_Stun_Timer_timeout():
modulate = Color("ff4848")
stun = false
I have also tried this way as well but still
sound doesnt play
I'm sorry, I'm still at work for an hour or so. I'll check back when I can sit down at my battlestation and see what I see. I've done this...yesterday 😛
Explode_sound is part of your enemy scene. You are playing the sound effect and then queue_freeing the enemy scene which is deleting the sound effect before it can play. You either need to wait to queue_free the enemy until the sound effect has finished playing or have the sound effect somewhere that does not get deleted.
Like I said, I was missing something very obvious 😛 Thanks for pointing that out, I saw it as soon as I sat down after work lol.
what will be the best idea to deal with?
I need the enemy to die right away when it's hp reaches 0
but if I set the time for the time for the sound to play and let queue_free
I think it would stay on the screen for a while?
I tried this on global script
extends Node
var node_creation_parent = null
var player = null
var camera = null
var explode_sound = preload("res://Sounds/Explode.mp3")
var enemy_death = false
var explode_sound_instances = []
var points = 0
func instance_node(node, location, parent):
var node_instance = node.instance()
parent.add_child(node_instance)
node_instance.global_position = location
return node_instance
func _process(delta):
if enemy_death == true:
var sound_instance = explode_sound.play()
if sound_instance != null:
explode_sound_instances.append(sound_instance)
```
func _process(delta):
if Global.player != null and !stun:
velocity = global_position.direction_to(Global.player.global_position)
elif stun:
velocity = lerp(velocity, Vector2(0, 0), 0.3)
global_position += velocity * speed * delta
if hp <= 0:
if Global.camera != null:
Global.camera.screen_shake(20, 0.1)
Global.enemy_death = true
Global.points += 10
if Global.node_creation_parent != null:
var blood_particles_instance = Global.instance_node(blood_particles, global_position, Global.node_creation_parent)
blood_particles_instance.rotation = velocity.angle()
var sound_instance = explode_sound.play()
if sound_instance != null:
explode_sound_instances.append(sound_instance)
queue_free()
and this on enemy
any idea..?
func _ready():
explosion_sound = $Explode
func _process(delta):
if Global.player != null and !stun:
velocity = global_position.direction_to(Global.player.global_position)
elif stun:
velocity = lerp(velocity, Vector2(0, 0), 0.3)
global_position += velocity * speed * delta
if hp <= 0:
if Global.camera != null:
Global.camera.screen_shake(40, 0.1)
Global.points += 10
if Global.node_creation_parent != null:
var blood_particles_instance = Global.instance_node(blood_particles, global_position, Global.node_creation_parent)
blood_particles_instance.rotation = velocity.angle()
explode()
queue_free()
func explode():
if explosion_sound:
explosion_sound.play()
while explosion_sound.is_playing():
yield(get_tree(), "idle_frame")
queue_free()
or is this a thing
still doesnt work..