i have this png file contain few skin and i just wonder if i can just change the skin of ball in game automatic with code. in my mind i thinking like godot move from skin to skin without me cutting the png file manually.
do you know how to do that? or maybe i just to lazy for not want to cutting it manually?
In the video, it’s a random texture loader though.
But the general idea stays the same:
onready var The_Texture_file : String #The texture
export var Variation : int
func ready():
The_Texture_file
match Variation: #Picks a match of skin
1: #Skin 1
The_texture_file = "res://Directory_of_skin_1" #sets the texture file to be loaded as skin 1
2: #Skin 2
The_texture_file = "res://Directory_of_skin_2" #sets the texture file to be loaded as skin 2
$Sprite.texture = load(The_texture_file) #this loads the texture file
well after watching it, i kinda get it what you mean. making random skin to generate.
but what i mean is like this one. lets say i want to take that fifth block, after it get hit it change to next block without me cutting it and put them in order.
so its like get height and weight of the sprite and move X, Y every time it get hit. so we dont need to put stuff in order and just call stuf with code.
@onready var sprite_2d_2 = $Sprite2D2 @export var num_frames: int = 4 # Total number of frames in the sprite sheet @export var frame_width: int = 32 # Width of each frame @export var frame_height: int = 16 # Height of each frame
var region
var current_frame : int = 0
func _ready():
sprite_2d_2.region_enabled = true #eneble region selection on image
region = Rect2(0, 0, frame_width, frame_height) #set the first image part
sprite_2d_2.region_rect = region
func _process(delta):
# Example hit detection - you should replace this with your actual hit detection logic
if Input.is_action_just_pressed(“ui_accept”): # Simulate a hit with the “Enter” key
on_hit()
func on_hit():
current_frame += 1
update_region()
func update_region():
var x = current_frame * frame_width
var y = 0 #asume every frame have same y, you can change it the way you like
region = Rect2(x,y, frame_width, frame_height)
sprite_2d_2.region_rect = region
All it is just a next frame in the production. I don’t really care how you do it. Different color. A different mask. Or, a different picture.
I think I see what’s going on. Everyone is getting sold on Godot 3.1 Because it uses the JTAC Node interface.