aniruby 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -4
- data/README.md +6 -6
- data/Rakefile +1 -1
- data/lib/aniruby/animation.rb +33 -16
- data/lib/aniruby/frame.rb +13 -4
- data/lib/aniruby/version.rb +2 -2
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 361fe4d0f4dddeca7090d35a7bb225440fd51c94c69d5b7ea0a0be8826437340
|
4
|
+
data.tar.gz: afb5d871c301e09df8559cd66e2609c408e810f9f3d48e68adaf851569f19a4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1d8d7b7c1fabdde8b84c68199463af199ed6bfdf7e5f7e7b684f5fc5a9abba315095655bb22904be5eb29c61877c4ae6f5f348a29971b2103e739506a6950f
|
7
|
+
data.tar.gz: d79b9b2f63047cad421027880c40723472a22fcf4f13e0444a4da89cb99aab772fc8eff1d1cacabb6c38ce568dd6276651f6d9b1d5b9fbf10cb738d19320b454
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## Unreleased
|
9
9
|
|
10
|
+
## 0.2.0 - 2023-09-02
|
11
|
+
|
12
|
+
This release brings mostly improvements and fixes, however there's not that much
|
13
|
+
new features yet.
|
14
|
+
|
15
|
+
### Added
|
16
|
+
|
17
|
+
- aliased `Animation#width` and `Animation#height` to `w` and `h` respectively, the same was done
|
18
|
+
for `Frame`.
|
19
|
+
|
20
|
+
### Changed
|
21
|
+
|
22
|
+
- `Animation#get_current_frame` is now `Animation#current_frame` as to not be redundant. Following that now `Animation#current_frame`(The accessor for the instance variable) is renamed to `Animation#position`.
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
|
26
|
+
- Previously methods like `Animation#done?` or `Animation#resume` didn't return `self`, so it wasn't possible to chaint them like this
|
27
|
+
```ruby
|
28
|
+
# Example
|
29
|
+
my_animation.pause.resume.duration(200)
|
30
|
+
```
|
31
|
+
now they do so you can do that.
|
32
|
+
|
10
33
|
## 0.1.3 - 2023-08-22
|
11
34
|
|
12
35
|
### Fixed
|
@@ -23,18 +46,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
23
46
|
|
24
47
|
### Changed
|
25
48
|
|
26
|
-
- Downcased the gem name in the gemspec
|
49
|
+
- Downcased the gem name in the gemspec.
|
27
50
|
|
28
51
|
## 0.1.1 - 2023-08-20
|
29
52
|
|
30
53
|
### Added
|
31
54
|
|
32
|
-
- Add .yardopts to included files
|
55
|
+
- Add .yardopts to included files.
|
33
56
|
|
34
57
|
### Fixed
|
35
58
|
|
36
|
-
- Required ruby not being used correctly in gemspec
|
59
|
+
- Required ruby not being used correctly in gemspec.
|
37
60
|
|
38
61
|
## 0.1.0 - 2023-08-20
|
39
62
|
|
40
|
-
Initial release
|
63
|
+
Initial release.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# AniRuby
|
2
2
|
|
3
|
-
|
3
|
+
![Gem (including prereleases)](https://img.shields.io/gem/v/aniruby?style=flat-square&color=blue)
|
4
4
|
|
5
5
|
Make sprite animations on Gosu simple and easy.
|
6
6
|
|
@@ -71,9 +71,9 @@ spritesheet will be divided like this:
|
|
71
71
|
|
72
72
|
![example spritesheet quads](assets/example_spritesheet_quads.png)
|
73
73
|
|
74
|
-
That
|
75
|
-
option so pixel animations
|
76
|
-
of the animation (or for every
|
74
|
+
That's the bare minimum to get an animation, of course you can enable Gosu's retro
|
75
|
+
option so pixel animations will still look crisp when scaled, enable looping or specify
|
76
|
+
the duration of the animation (or for every frame even!).
|
77
77
|
|
78
78
|
In the example above we initialize the animation with retro off, looping on and
|
79
79
|
with a duration of 0.15 (150ms) for every frame. So we'll get something like this:
|
@@ -84,7 +84,7 @@ Ain't that nice?
|
|
84
84
|
|
85
85
|
### Drawing
|
86
86
|
|
87
|
-
You can draw an animation like any other `Gosu::Image`!
|
87
|
+
You can draw an animation like any other `Gosu::Image`! An animation has both
|
88
88
|
`Animation#draw` and `Animation#draw_rot`, these methods mimic the ones on Gosu, so you don't
|
89
89
|
have to learn anything new.
|
90
90
|
|
@@ -114,4 +114,4 @@ Then you can use rake to build or test gem.
|
|
114
114
|
|
115
115
|
## License
|
116
116
|
|
117
|
-
[MIT](LICENSE)
|
117
|
+
This library is licensed under the [MIT](LICENSE) license.
|
data/Rakefile
CHANGED
data/lib/aniruby/animation.rb
CHANGED
@@ -6,8 +6,8 @@ module AniRuby
|
|
6
6
|
# @return [AniRuby::Frames] The collection of frames this animation uses
|
7
7
|
attr_accessor :frames
|
8
8
|
# @return [Integer] The current frame index of the animation
|
9
|
-
attr_accessor :
|
10
|
-
# @return [Boolean] The loop
|
9
|
+
attr_accessor :position
|
10
|
+
# @return [Boolean] The loop parameter
|
11
11
|
attr_accessor :loop
|
12
12
|
|
13
13
|
# Create a new animation
|
@@ -22,15 +22,18 @@ module AniRuby
|
|
22
22
|
# provided they will be mapped to each frame of the
|
23
23
|
# animation. The default for each frame is 0.1.
|
24
24
|
#
|
25
|
-
#
|
26
25
|
# @return [Animation] A new animation ready to play
|
27
|
-
def initialize(spritesheet,
|
26
|
+
def initialize(spritesheet,
|
27
|
+
frame_w, frame_h,
|
28
|
+
retro = false,
|
29
|
+
loop = true,
|
30
|
+
*durations)
|
28
31
|
@frame_w = frame_w
|
29
32
|
@frame_h = frame_h
|
30
33
|
|
31
34
|
@loop = loop
|
32
35
|
|
33
|
-
@
|
36
|
+
@position = 0
|
34
37
|
@pause = false
|
35
38
|
|
36
39
|
@frames = AniRuby::Frames.new(Gosu::Image.load_tiles(spritesheet,
|
@@ -55,22 +58,26 @@ module AniRuby
|
|
55
58
|
#
|
56
59
|
# @return [Integer]
|
57
60
|
def width
|
58
|
-
@frames[@
|
61
|
+
@frames[@position].width
|
59
62
|
end
|
60
63
|
|
64
|
+
alias :w :width
|
65
|
+
|
61
66
|
# Get the height of the current frame's image
|
62
67
|
#
|
63
68
|
# @return [Integer]
|
64
69
|
def height
|
65
|
-
@frames[@
|
70
|
+
@frames[@position].height
|
66
71
|
end
|
67
72
|
|
73
|
+
alias :h :height
|
74
|
+
|
68
75
|
# Update the animation, advancing the frame counter. Note that this won't do
|
69
76
|
# do anything if the animation is paused or has finished
|
70
77
|
def update
|
71
78
|
return if done? || paused?
|
72
79
|
|
73
|
-
@
|
80
|
+
@position += 1 if frame_expired?
|
74
81
|
end
|
75
82
|
|
76
83
|
# Draw the animation
|
@@ -93,7 +100,7 @@ module AniRuby
|
|
93
100
|
|
94
101
|
frame.sprite.draw(x, y, z, scale_x, scale_y, color, mode)
|
95
102
|
|
96
|
-
@
|
103
|
+
@position = 0 if @loop && done?
|
97
104
|
end
|
98
105
|
|
99
106
|
# Draw the animation rotated, with its rotational center at (x, y).
|
@@ -123,7 +130,7 @@ module AniRuby
|
|
123
130
|
frame.sprite.draw_rot(x, y, z, angle, center_x, center_y, scale_x, scale_y, color, mode)
|
124
131
|
|
125
132
|
# Loop the animation
|
126
|
-
@
|
133
|
+
@position = 0 if @loop && done?
|
127
134
|
end
|
128
135
|
|
129
136
|
# Pause the animation
|
@@ -131,6 +138,8 @@ module AniRuby
|
|
131
138
|
# (see {resume})
|
132
139
|
def pause
|
133
140
|
@pause = true
|
141
|
+
|
142
|
+
self
|
134
143
|
end
|
135
144
|
|
136
145
|
# Resume the animation
|
@@ -138,18 +147,24 @@ module AniRuby
|
|
138
147
|
# (see {pause})
|
139
148
|
def resume
|
140
149
|
@pause = false
|
150
|
+
|
151
|
+
self
|
141
152
|
end
|
142
153
|
|
143
154
|
# Set the animation to the beginning frame
|
144
155
|
def reset
|
145
|
-
@
|
156
|
+
@position = 0
|
157
|
+
|
158
|
+
self
|
146
159
|
end
|
147
160
|
|
148
161
|
# Set the duration for all frames in the animation
|
149
162
|
#
|
150
163
|
# @param ms [Float] The new duration in milliseconds
|
151
164
|
def duration(ms)
|
152
|
-
@frames.each { |frame| frame.duration = ms}
|
165
|
+
@frames.each { |frame| frame.duration = ms }
|
166
|
+
|
167
|
+
self
|
153
168
|
end
|
154
169
|
|
155
170
|
# Is the animation finished?
|
@@ -157,7 +172,9 @@ module AniRuby
|
|
157
172
|
# @return [Boolean]
|
158
173
|
# @note This method will return true in intervals if the animation loops
|
159
174
|
def done?
|
160
|
-
true if @
|
175
|
+
true if @position == @frames.count - 1
|
176
|
+
|
177
|
+
false
|
161
178
|
end
|
162
179
|
|
163
180
|
# Is the animation paused?
|
@@ -172,8 +189,8 @@ module AniRuby
|
|
172
189
|
# Get the current frame
|
173
190
|
#
|
174
191
|
# @return [AniRuby::Frame]
|
175
|
-
def
|
176
|
-
@frames[@
|
192
|
+
def current_frame
|
193
|
+
@frames[@position % @frames.count]
|
177
194
|
end
|
178
195
|
|
179
196
|
# Has the current frame's duration expired?
|
@@ -181,7 +198,7 @@ module AniRuby
|
|
181
198
|
now = Gosu.milliseconds / 1000.0
|
182
199
|
@last_frame ||= now
|
183
200
|
|
184
|
-
if (now - @last_frame) > @frames[@
|
201
|
+
if (now - @last_frame) > @frames[@position].duration
|
185
202
|
@last_frame = now
|
186
203
|
end
|
187
204
|
end
|
data/lib/aniruby/frame.rb
CHANGED
@@ -3,8 +3,17 @@ module AniRuby
|
|
3
3
|
# A frame has a sprite that's Gosu::Image and a duration specified in
|
4
4
|
# milliseconds
|
5
5
|
class Frame
|
6
|
-
|
7
|
-
|
6
|
+
# @return [Float]
|
7
|
+
attr_accessor :duration
|
8
|
+
|
9
|
+
# @return [Gosu::Image]
|
10
|
+
attr_accessor :sprite
|
11
|
+
|
12
|
+
# @return [Integer]
|
13
|
+
attr_reader :width, :height
|
14
|
+
|
15
|
+
alias :w :width
|
16
|
+
alias :h :height
|
8
17
|
|
9
18
|
# Create a new frame
|
10
19
|
#
|
@@ -16,8 +25,8 @@ module AniRuby
|
|
16
25
|
@sprite = sprite
|
17
26
|
@duration = duration
|
18
27
|
|
19
|
-
@
|
20
|
-
@
|
28
|
+
@width = @sprite.width
|
29
|
+
@height = @sprite.height
|
21
30
|
end
|
22
31
|
end
|
23
32
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chadow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.17.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-reporters
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.6.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 13.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 13.0.0
|
41
69
|
description: |
|
42
70
|
Library for painless sprite animations on Gosu, with a easy
|
43
71
|
and nifty API, made in pure Ruby with no dependencies at all!
|
@@ -74,7 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
102
|
- - ">="
|
75
103
|
- !ruby/object:Gem::Version
|
76
104
|
version: '0'
|
77
|
-
requirements:
|
105
|
+
requirements:
|
106
|
+
- Gosu installed and working
|
78
107
|
rubygems_version: 3.4.19
|
79
108
|
signing_key:
|
80
109
|
specification_version: 4
|