Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Xenapibe |
Hello I want to create a store system to my game. But I have some issues, I want to change sprite when I pressed the buy button. But I can’t create a algorithm for this can someone help me ? So I want to change my sprite texture with global script. How can I do that?
Godot Version : 3.5.1
Game Platform : Android
You will need to share a bit more detail about how you implemented your button. Are you using a Node2D or a Sprite?
Did you see that there a TextureButton Control node in Godot?
Can you share the code that draws your button?
Juxxec | 2022-11-30 09:22
My Button code
func _on_BuyCharacter_pressed():
if GlobalLevel.GlobalCoin >= 0:
$StorePanel/CharacterBuy/Sold.visible = true
$StorePanel/CharacterBuy/Goblin.self_modulate = Color.crimson
$StorePanel/CharacterBuy/Locked.visible = true
$StorePanel/CharacterBuy/Goblin/Particles2D.visible = false
GlobalLevel.GlobalCoin = GlobalLevel.GlobalCoin - 0
$CollectedCoins.text = str(GlobalLevel.GlobalCoin)
GlobalLevel.save_coin()
Xenapibe | 2022-11-30 09:23
And my Global script for saving and loading skin
func save_skin():#save skin
var SaveSkin = File.new()
var data: Dictionary = {"skin": GlobalSkin}
SaveSkin.open("user://skin.dat", File.WRITE)
SaveSkin.store_var(data)
SaveSkin.close()
func load_skin():#load skin
var SaveSkin = File.new()
if !SaveSkin.file_exists("user://skin.dat"):
return
SaveSkin.open("user://skin.dat", File.READ)
var data = SaveSkin.get_var()
GlobalSkin = data["skin"]
SaveSkin.close()
Xenapibe | 2022-11-30 09:24
Also my GlobalSkin variable
var GlobalSkin: Dictionary ={"Goblin":Goblin,
"Player": DefaultPlayer}
Xenapibe | 2022-11-30 09:25
If you want to check the images of my code you can go my reddit post for this issue
Reddit post
Xenapibe | 2022-11-30 09:26