Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | piever | |
Old Version | Published before Godot 3 was released. |
Hi!
I’m a bit of a newcomer to Godot (and game development in general) and I’m struggling on a simple issue. I have an example sky background for a game, which I can repeat tiling all the space I need using Region and Repeat (solution found here). I’d like to animate the sky a bit and I have about 4 frames I’d like to cycle through which I though of doing using animated-sprite. However animated-sprites dont’ have the Region and Repeat option to tile space. The only solution I could find was to do a TextureFrame and I would keep setting a different texture (say at 4Hz) from code, but this feels very suboptimal and I’m afraid could slow down the game.
What’s the recommended solution? Is there something basic that I’m missing?
That could be solved using custom drawing for sure (with a script), but I don’t have a friendly solution using only nodes (It would involve AnimationPlayer
, AtlasTexture
and TextureFrame
).
Zylann | 2017-05-26 17:09
Thanks for the tip! I’ve tried to play a bit with custom drawing and came up with this: is this what you had in mind or there are more elegant/performant solutions? The main thing that I’d like to improve is the manual typing of what to preload. I don’t seem to be able to do it in a loop because preload requires constant strings.
var i = 0
var texture
var frame1 = preload("res://frames/bg1.png")
var frame2 = preload("res://frames/bg2.png")
var frame3 = preload("res://frames/bg3.png")
var frame4 = preload("res://frames/bg4.png")
var frames = [frame1, frame2, frame3, frame4]
func _draw():
for pt in pts:
draw_texture(texture,pt)
func _on_Timer_timeout():
i = (i+1) % 4
texture = frames[i]
update()
piever | 2017-05-26 18:46