Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PointDexter07 |
extends Node2D#Spawner
const enemy = preload(“res://enemy.tscn”)
func _on_Timer_timeout():
randomize()
var posX = rand_range(700, 1250)
var posY = 0
var fall = enemy.instance()
add_child(fall)
fall.position = Vector2(posX, posY)
$Timer.wait_time = max(.01, $Timer.wait_time - 0.01)
extends Node#global.gd
var letters = [“a”, “b”, “c”]
var sel = “”
var temp = “”
var A = “a”
var B = “b”
var C = “c”
signal tile_destroyed
func _process(delta):
randomize()
sel = letters[rand_range(0, len(letters))]
func letterDestroyed():
emit_signal("tile_destroyed")
extends Area2D
var wordA = “”
var motion = Vector2()
onready var sprite = get_node(“Sprite”)#Get’s the Sprite of the node
var A = preload(“res://A.png”)#Image A
var B = preload(“res://B.png”)#Image B
var C = preload(“res://C.png”)#Image C
func _ready():
if global.sel == global.A:
print(global.sel + “-”)
print(global.A + “-”)
sprite.set_texture(A)#Changes the image to A if global.sel = A
pass
if global.sel == global.B:
print(global.sel + "+")
print(global.B + "+")
sprite.set_texture(B)#Changes the image to B if global.sel = B
pass
if global.sel == global.C:
print(global.sel + "'")
print(global.C + "'")
sprite.set_texture(C)#Changes the image to C if global.sel = C
pass
func _physics_process(delta):
motion.y = 170 * delta
translate(motion)
func _on_Node2D_input_event(viewport, event, shape_idx):
if event.is_pressed():
global.temp = global.sel
print(global.temp + " if pressed")
if global.temp == global.A:
global.temp = global.A
elif global.temp == global.B:
global.temp = global.B
elif global.temp == global.C:
global.temp = global.C
global.letterDestroyed()#Global signal to display the letter if Area2D is destroyed
queue_free()
extends RichTextLabel
const sp = preload(“res://enemy.tscn”)
func _ready():
global.connect(“tile_destroyed”, self, “update_text”)
update_text()
func update_text(): #add letters to the screen(RichTextLabel)
if global.temp == global.A:
add_text(global.temp)
print(global.temp)
elif global.temp == global.B:
add_text(global.temp)
print(global.temp)
elif global.temp== global.C:
add_text(global.temp)
print(global.temp)
Can’t see what’s the issue here! Your code runs fine: if I click on an enemy (spawning at a random x-position at the top border of the screen and moving downwards with constant velocity), it’s freed and the letter currently saved in global.temp
is added to the RichTextLabel. Which seems to be exactly what you are asking for?
Also please format your code properly. Every line in a code block has to be indented, use the Preview below the editor window to make sure everything looks alright. You can still edit your post by clicking on the three dots at the lower right of your question.
njamster | 2020-03-05 12:15
Thanks and my bad this is the first time I’m posting and I didn’t explain it well, my problem is when I clicked the falling letters for example A, sometimes a “C” would display. I random generate the letters in global.gd in the func _process(delta): and even though I save the in global.temp I get that problem.
PointDexter07 | 2020-03-05 17:10