Godot Engine

Godot Engine

Raptec Apr 29, 2021 @ 7:18pm
Change scene don´t work
Is something basic, but at the same time don´t work, I want when the game start and show me my first scene (a simple image/sprite) , then the player just have to press the spacebar to advance the next scene,
I don´t want the player press a pre-made button, just the spacebar, nothing more,
already try make the script in a control, kinematicbody2d, a sprite, an animationplayer(from the top-down RPG example), changing his appropiate extend type, but nothing works, the game just ignore the spacebar press, it even give me a # warning-ignore:return_value_discarded, in the middle of the code,
i also try load(), i even try a more advanced scene in which you can attack with one character with spacebar and that key work without problems.


extends Control

func _ready():
if Input.is_action_just_pressed("ataque"):
# warning-ignore:return_value_discarded
get_tree().change_scene("res://0B Fondos/00b Historia.tscn")


In the warning system: [Ignore] Line 9 (RETURN_VALUE_DISCARDED): The function 'change_scene()' return a value, but this value is never used.
< >
Showing 1-3 of 3 comments
Raptec Apr 30, 2021 @ 12:08am 
Ugh, i manage to fix it, i have to make a button which covers all the screen, then add to the main scene a Script with:

extends Control

func _on_Button_pressed():
get_tree().change_scene("res://0B_Fondos/00b_Historia.tscn")

Then go to the inspector of the button and check "Flat" option (that make the button invisible) and "Shortcut in tooltip",
Then go to "Shortcut" add a new shortcut type "InputEventKey", Then look where it say "Scancode", there you should put a number which is the key you want to asign, the full list of numbers and which key they belong is here:

https://docs.godotengine.org/en/3.0/classes/class_@globalscope.html

I hope this work for other people too
calmproto Apr 30, 2021 @ 12:49pm 
Keyboard events are captured in InputEventKey. While it's recommended to use input actions instead, there may be cases where you want to specifically look at key events. For this example, let's check for the spacebar:
func _input(event):
if event is InputEventKey and event.pressed:
if event.scancode == KEY_SPACE:
print("Spacebar was pressed")
https://docs.godotengine.org/en/3.3/tutorials/inputs/input_examples.html?highlight=keypress#keyboard-events
https://docs.godotengine.org/en/3.3/classes/class_%40globalscope.html#enum-globalscope-keylist

Raptec May 1, 2021 @ 4:08am 
Nice to know and have more options
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Apr 29, 2021 @ 7:18pm
Posts: 3