|
|
|
 |
Reply From: |
Zylo_X |
Hello
First of all please describe your problem in more specific way
I think some parts of your code are incorrect
And If you are using TextureRect then you can use set_texture()
Like this example :
@onready var Back= $BackGame
var New_Background= preload(address)
func input(ev):
if Input.is_key_pressed(Key_8):
Back.set_texture(New_Background)
_process(delta) :
input(ev)
Using the _input(event):
function would be better because you dont have to call it in _process(delta):
For example :
@onready var Back= $BackGame
var New_Background= preload(address)
func _input(event): # No need to call this in _process
if Input.is_key_pressed(Key_8):
Back.set_texture(New_Background)
Enfyna | 2023-03-26 09:28
I didn’t know about this function
It seems a pretty good way to handle inputs
Thanks !!!
Zylo_X | 2023-03-26 09:40
Thanks
I wrote it but it still don`t work when I run all the project but it work when I run just the scene.
and could you tell me what @onready do , please?
This is all my code in this scene:
The other keys script work in both run but the key 8 script just work in the scene project.
@onready var Back = $BackGame
var new_background = preload (I wrote the address)
func _input(event):
if Input.is_key_pressed(KEY_8):
Back.set_texture (New_Background)
How ?
Here there is no object to select an image or maybe there is and i dont know becuase i am new
here check this pic i tried it and it worked !!!
Screenshot-20230326-085831 hosted at ImgBB — ImgBB
image of the node + code
Screenshot-20230326-090034 hosted at ImgBB — ImgBB
extends Node2D
@onready var Back = $Background
var new_Background = preload("res://Data/back_cave.png")
var Old_Background = preload("res://Data/sci_fi_bg1.jpg")
func _input(event):
if Input.is_key_pressed(KEY_8):
Back.set_texture(new_Background)
elif Input.is_key_pressed(KEY_7):
Back.set_texture(Old_Background)
note : you have to use the numbers not the keypad ( under the numlock button)
Zylo_X | 2023-03-26 18:02