aniruby 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +52 -13
- data/Rakefile +1 -1
- data/lib/aniruby/animation.rb +9 -9
- data/lib/aniruby/frame.rb +9 -2
- data/lib/aniruby/frames.rb +3 -1
- data/lib/aniruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f06e5010221982c6ac29ff4f0670f1315236397182aa8df23bbc199b411f959
|
4
|
+
data.tar.gz: 06752b16a07eae712c689130ac7bfaf41b433a6fc18a2bc26339a6fbba0c14eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07dfe64289a335ffc010d07eb7596e8cdea2cdb55084e81a2d789045bb7b3be59471dcc8a8735aee5e5f11ece070566c8ebf05d1e9bf2aadd3af31603c691b7b
|
7
|
+
data.tar.gz: a47f0888419c88b9ea73d742f283894a0fbb07c8d1bebd9c8bd5fc1a9db367bf16d9da62ab434a6e1afc3f44fd4ad97c8527b05eeb787bc0f298a01d43d4e6a1
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,19 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
##
|
8
|
+
## Unreleased
|
9
|
+
|
10
|
+
## 0.1.3 - 2023-08-22
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
|
14
|
+
- Undefined method error in animation, when using `size` on `AniRuby::Frames`, now
|
15
|
+
use `Enumerable#count` instead.
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- The way milliseconds are used as duration, before you'll have to use whole numbers
|
20
|
+
(1000 is a second, 500 half a second and so on), now we can just use floats for that (1.0 as a second, 0.5 half a second and so on).
|
9
21
|
|
10
22
|
## 0.1.2 - 2023-08-20
|
11
23
|
|
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# AniRuby
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/aniruby.svg)](https://badge.fury.io/rb/aniruby)
|
4
|
+
|
3
5
|
Make sprite animations on Gosu simple and easy.
|
4
6
|
|
5
7
|
## Summary
|
6
8
|
|
7
9
|
This library will provide you with a nice n easy interface to do sprite animations
|
8
|
-
on [Gosu](https://www.libgosu.org/), while being as nifty as possible
|
10
|
+
on [Gosu](https://www.libgosu.org/), while being as nifty and simple as possible.
|
9
11
|
|
10
|
-
The library is made in pure Ruby with no dependencies at all (except Gosu, of course)
|
12
|
+
The library is made in pure Ruby with no dependencies at all (except Gosu, of course) so
|
13
|
+
its quite lightweight.
|
11
14
|
|
12
15
|
## Install
|
13
16
|
|
@@ -18,14 +21,14 @@ You can install the gem with the following command:
|
|
18
21
|
or use it with a bundle:
|
19
22
|
|
20
23
|
```ruby
|
21
|
-
# Somewhere in
|
24
|
+
# Somewhere in your Gemfile
|
22
25
|
|
23
26
|
gem 'aniruby'
|
24
27
|
```
|
25
28
|
|
26
29
|
## Getting Started
|
27
30
|
|
28
|
-
|
31
|
+
The smallest example:
|
29
32
|
|
30
33
|
```ruby
|
31
34
|
|
@@ -38,10 +41,11 @@ class MyWindow < Gosu::Window
|
|
38
41
|
|
39
42
|
@animation = AniRuby::Animation.new('my_spritesheet.png', 32, 32,
|
40
43
|
false, true,
|
41
|
-
|
44
|
+
0.15)
|
42
45
|
end
|
43
46
|
|
44
47
|
def update
|
48
|
+
# Remember to update your animation!
|
45
49
|
@animation.update
|
46
50
|
end
|
47
51
|
|
@@ -56,22 +60,57 @@ end
|
|
56
60
|
When you create a animation, you'll need to have an *spritesheet*, where you have
|
57
61
|
each sprite of the animation, that's the first argument to `Animation#new`, then
|
58
62
|
you'll need the dimensions of each individual sprite on your spritesheet, in the
|
59
|
-
example provided each sprite in the spritesheet is 32x32.
|
63
|
+
example provided we assume each sprite in the spritesheet is 32x32. Take for example
|
64
|
+
the following spritesheet courtesy of penzilla on [Itch.io](https://penzilla.itch.io/hooded-protagonist)
|
65
|
+
|
66
|
+
![example spritesheet](assets/example_spritesheet.png)
|
67
|
+
|
68
|
+
when we load it, it'll be divided into different image based on the individual
|
69
|
+
dimensions of each sprite, so if we specify 32 as width and 32 as height then the
|
70
|
+
spritesheet will be divided like this:
|
71
|
+
|
72
|
+
![example spritesheet quads](assets/example_spritesheet_quads.png)
|
73
|
+
|
74
|
+
That is the bare minimum, to get an animation, of course you can use Gosu's retro
|
75
|
+
option so pixel animations when scaled will still look crisp, looping or the duration
|
76
|
+
of the animation (or for every individual frame even!).
|
77
|
+
|
78
|
+
In the example above we initialize the animation with retro off, looping on and
|
79
|
+
with a duration of 0.15 (150ms) for every frame. So we'll get something like this:
|
80
|
+
|
81
|
+
![example spritesheet result](assets/example_spritesheet_result.gif)
|
82
|
+
|
83
|
+
Ain't that nice?
|
84
|
+
|
85
|
+
### Drawing
|
86
|
+
|
87
|
+
You can draw an animation like any other `Gosu::Image`! Sn animation has both
|
88
|
+
`Animation#draw` and `Animation#draw_rot`, these methods mimic the ones on Gosu, so you don't
|
89
|
+
have to learn anything new.
|
90
|
+
|
91
|
+
### Extras
|
92
|
+
|
93
|
+
Each `Animation` has extra helpful methods, like `pause` & `unpause`, `reset`,
|
94
|
+
`done?`, etc. I recommend you to look on the source, its pretty small and easy to
|
95
|
+
understand, or build the YARD documentation with
|
96
|
+
|
97
|
+
`rake doc`
|
98
|
+
|
99
|
+
## Development
|
60
100
|
|
61
|
-
|
62
|
-
and duration (for each individual frame too!).
|
101
|
+
First clone this repo locally:
|
63
102
|
|
64
|
-
|
65
|
-
to come to live!
|
103
|
+
`git clone https://github.com/Chadowo/aniruby`
|
66
104
|
|
67
|
-
|
68
|
-
much more than single coordinates. there's `Animation#draw_rot` too!
|
105
|
+
Then you can use rake to build or test gem.
|
69
106
|
|
70
107
|
## Roadmap
|
71
108
|
|
72
109
|
- more fine-grained control of animation
|
73
110
|
- being able to make an animation stitching `Gosu::Image`'s together
|
74
|
-
- mirroring
|
111
|
+
- mirroring
|
112
|
+
- inverse animation
|
113
|
+
- multiple animation from a single spritesheet
|
75
114
|
|
76
115
|
## License
|
77
116
|
|
data/Rakefile
CHANGED
data/lib/aniruby/animation.rb
CHANGED
@@ -17,11 +17,11 @@ module AniRuby
|
|
17
17
|
# @param frame_h [Integer] The height of each individual frame
|
18
18
|
# @param retro [Boolean] If true, the animation will not be interpolated when scaled
|
19
19
|
# @param loop [Boolean] If true, the animation will loop indefinitely
|
20
|
-
# @param durations [
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
20
|
+
# @param durations [Float] The duration of the frames in MS (0.5 is half a second,
|
21
|
+
# 1.0 a second, etc). If there's more than one duration
|
22
|
+
# provided they will be mapped to each frame of the
|
23
|
+
# animation. The default for each frame is 0.1.
|
24
|
+
#
|
25
25
|
#
|
26
26
|
# @return [Animation] A new animation ready to play
|
27
27
|
def initialize(spritesheet, frame_w, frame_h, retro = false, loop = true, *durations)
|
@@ -147,7 +147,7 @@ module AniRuby
|
|
147
147
|
|
148
148
|
# Set the duration for all frames in the animation
|
149
149
|
#
|
150
|
-
# @param ms [
|
150
|
+
# @param ms [Float] The new duration in milliseconds
|
151
151
|
def duration(ms)
|
152
152
|
@frames.each { |frame| frame.duration = ms}
|
153
153
|
end
|
@@ -157,7 +157,7 @@ module AniRuby
|
|
157
157
|
# @return [Boolean]
|
158
158
|
# @note This method will return true in intervals if the animation loops
|
159
159
|
def done?
|
160
|
-
true if @current_frame == @frames.
|
160
|
+
true if @current_frame == @frames.count - 1
|
161
161
|
end
|
162
162
|
|
163
163
|
# Is the animation paused?
|
@@ -173,12 +173,12 @@ module AniRuby
|
|
173
173
|
#
|
174
174
|
# @return [AniRuby::Frame]
|
175
175
|
def get_current_frame
|
176
|
-
@frames[@current_frame % @frames.
|
176
|
+
@frames[@current_frame % @frames.count]
|
177
177
|
end
|
178
178
|
|
179
179
|
# Has the current frame's duration expired?
|
180
180
|
def frame_expired?
|
181
|
-
now = Gosu.milliseconds
|
181
|
+
now = Gosu.milliseconds / 1000.0
|
182
182
|
@last_frame ||= now
|
183
183
|
|
184
184
|
if (now - @last_frame) > @frames[@current_frame].duration
|
data/lib/aniruby/frame.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
|
2
2
|
module AniRuby
|
3
|
-
# A frame has a sprite and a duration in
|
3
|
+
# A frame has a sprite that's Gosu::Image and a duration specified in
|
4
|
+
# milliseconds
|
4
5
|
class Frame
|
5
6
|
attr_accessor :duration, :sprite
|
6
7
|
attr_reader :w, :h
|
7
8
|
|
8
|
-
|
9
|
+
# Create a new frame
|
10
|
+
#
|
11
|
+
# @param sprite [Gosu::Image]
|
12
|
+
# @param duration [Float]
|
13
|
+
#
|
14
|
+
# @return [Frame]
|
15
|
+
def initialize(sprite, duration = 0.1)
|
9
16
|
@sprite = sprite
|
10
17
|
@duration = duration
|
11
18
|
|
data/lib/aniruby/frames.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
module AniRuby
|
3
|
-
# Collection of frames
|
3
|
+
# Collection of frames
|
4
4
|
class Frames
|
5
5
|
include Enumerable
|
6
6
|
|
@@ -14,6 +14,8 @@ module AniRuby
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# @param index [Integer]
|
17
|
+
#
|
18
|
+
# @return [Frame]
|
17
19
|
def [](index)
|
18
20
|
@frames[index]
|
19
21
|
end
|
data/lib/aniruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aniruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chadow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|