From 1392e90b16f56980aeb0d51c38ce33b82ed0e185 Mon Sep 17 00:00:00 2001 From: realtradam Date: Fri, 9 Jul 2021 14:08:33 -0400 Subject: . --- run.rb | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 run.rb (limited to 'run.rb') diff --git a/run.rb b/run.rb new file mode 100644 index 0000000..7992eb5 --- /dev/null +++ b/run.rb @@ -0,0 +1,58 @@ +require 'ruby2d' + +# Number of sprites in the sheet, automatically gets calculated +@iter = 0 + +# Displays the sprite index +@text = Text.new( + @iter, + x:0, y: 0, + size: 20, +) + +# Amount of sprites in rows/columns +@rows = 13 +@columns = 23 + +# Size of an individual sprite +@width = 64 +@height = 64 + +# Holds manual coordinates +@animations = {} + +# Generates the manual coordinates +(0...@rows).each do |row| + (0...@columns).each do |column| + @animations[@iter] = [{ + x: column * @width, y: row * @height, + width: @width, height: @height + }] + @iter += 1 + end +end + +# The sprite +@sprite = Sprite.new( + 'sheet.png', + x: 50, y:50, + clip_width: 64, + clip_height: 64, + time: 300, + animations: @animations +) + +# The frame number of Ruby2D +@frame = 0 + +update do + @frame += 1 + @sprite.play( + animation: ((@frame/30) % @iter), + loop: true + ) + @text.text = ((@frame/30) % @iter) + +end + +show -- cgit v1.2.3