ChocolateBird/widgets/BattleScene.gd

31 lines
1.1 KiB
GDScript3
Raw Normal View History

2023-08-15 16:20:40 +09:30
extends ReferenceRect
const battle_bg_shader = preload('res://shaders/tilemap_shader.gdshader')
var bg: SpriteLoader.BattleBackground
var pal_l: int
var atlas_l: int
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var battle_bg_mat := ShaderMaterial.new()
battle_bg_mat.shader = battle_bg_shader
$background.material = battle_bg_mat
set_bg(1)
func set_bg(index: int) -> void:
self.bg = SpriteLoader.battle_backgrounds[index]
self.pal_l = len(self.bg.palette_texs)
self.atlas_l = len(self.bg.tile_atlas_texs)
$background.texture = self.bg.tilemap_tex
$background.material.set_shader_param('palette', self.bg.palette_texs[0])
$background.material.set_shader_param('tile_atlas', self.bg.tile_atlas_texs[0])
# Called every frame. 'delta' is the elapsed time since the previous frame.
var t := 0.0
func _process(delta: float) -> void:
if not self.bg:
return
self.t = fmod(self.t + delta, 2.0)
$background.material.set_shader_param('palette', self.bg.palette_texs[int(self.t * 30) % self.pal_l])
$background.material.set_shader_param('tile_atlas', self.bg.tile_atlas_texs[int(self.t * 7.5) % self.atlas_l])