summaryrefslogtreecommitdiffhomepage
path: root/run.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-07-09 14:08:33 -0400
committerrealtradam <[email protected]>2021-07-09 14:08:33 -0400
commit1392e90b16f56980aeb0d51c38ce33b82ed0e185 (patch)
treee5418adef7bed06b369a7f6da21be6ac947d2c4c /run.rb
downloadruby2d-spritesheet-1392e90b16f56980aeb0d51c38ce33b82ed0e185.tar.gz
ruby2d-spritesheet-1392e90b16f56980aeb0d51c38ce33b82ed0e185.zip
.
Diffstat (limited to 'run.rb')
-rw-r--r--run.rb58
1 files changed, 58 insertions, 0 deletions
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