aniruby 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -9
- data/README.md +23 -10
- data/Rakefile +1 -21
- data/lib/aniruby/animation.rb +39 -25
- data/lib/aniruby/frame.rb +2 -3
- data/lib/aniruby/frames.rb +0 -1
- data/lib/aniruby/version.rb +1 -2
- data/lib/aniruby.rb +4 -6
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91784f282491084327d6f2317ad87316de4eae20a1bd06a4c63cebb56eb8a159
|
4
|
+
data.tar.gz: 5425f60a700e2ab366a15583c5bf3860f3bd7ff5cf540d45a21cfd7e4176b44b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40b40a12aad67d97800e999db54887428c89314b35a2aa2a6102fbcdbc544b8cfa5079bc21b2e9b2be3397862e729d676bdb1ba456b9ffdaae6e1ec1d3b05325
|
7
|
+
data.tar.gz: f37a4474aecf9e50c87e8340a218ba4845ba2900b0a3b4b5874b8b79db73d18897a315567e9402173e47aa1931380ef9208831f52d603525f689f40e1b5629f1
|
data/CHANGELOG.md
CHANGED
@@ -7,7 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## Unreleased
|
9
9
|
|
10
|
-
## 0.2.
|
10
|
+
## [0.2.2] - 2023-12-27
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Aliased `Animation#reset` to `Animation#reset!`.
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Arguments `retro` and `loop` from `Animation#new` are now keyword arguments.
|
19
|
+
- Renamed "position" attribute from `Animation` to "cursor".
|
20
|
+
- Passing a negative value as duration to `Animation#new` will default to 0.1.
|
21
|
+
|
22
|
+
## [0.2.1] - 2023-09-07
|
11
23
|
|
12
24
|
### Fixed
|
13
25
|
|
@@ -18,12 +30,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
18
30
|
- **Important**: There was a error in `Animation#done?` too, where it'll return `false` always
|
19
31
|
independently of if the animation was finished, this was because I forgot to add a `return` in
|
20
32
|
the condition check for the `true`.
|
21
|
-
- `Animation#update` now resets the animation, instead of `Animation#draw`
|
22
|
-
or `Animation#draw_rot` (I know, that sounds
|
33
|
+
- Internally, `Animation#update` now resets the animation, instead of `Animation#draw`
|
34
|
+
or `Animation#draw_rot` (I know, that sounds counterintuitive). This (I think) fixes a precision problem when drawing the last frame
|
23
35
|
of an animation, in the which it was drawn for less time than required.
|
24
36
|
|
25
|
-
|
26
|
-
## 0.2.0 - 2023-09-02
|
37
|
+
## [0.2.0] - 2023-09-02
|
27
38
|
|
28
39
|
This release brings mostly improvements and fixes, however there's not that much
|
29
40
|
new features yet.
|
@@ -39,7 +50,7 @@ for `Frame`.
|
|
39
50
|
|
40
51
|
### Fixed
|
41
52
|
|
42
|
-
- Previously methods like `Animation#
|
53
|
+
- Previously methods like `Animation#pause?` or `Animation#resume` didn't return `self`, so it wasn't possible to chain them like this
|
43
54
|
```ruby
|
44
55
|
# Example
|
45
56
|
my_animation.pause.resume.duration(200)
|
@@ -58,13 +69,13 @@ for `Frame`.
|
|
58
69
|
- The way milliseconds are used as duration, before you'll have to use whole numbers
|
59
70
|
(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).
|
60
71
|
|
61
|
-
## 0.1.2 - 2023-08-20
|
72
|
+
## [0.1.2] - 2023-08-20
|
62
73
|
|
63
74
|
### Changed
|
64
75
|
|
65
76
|
- Downcased the gem name in the gemspec.
|
66
77
|
|
67
|
-
## 0.1.1 - 2023-08-20
|
78
|
+
## [0.1.1] - 2023-08-20
|
68
79
|
|
69
80
|
### Added
|
70
81
|
|
@@ -74,6 +85,15 @@ for `Frame`.
|
|
74
85
|
|
75
86
|
- Required ruby not being used correctly in gemspec.
|
76
87
|
|
77
|
-
## 0.1.0 - 2023-08-20
|
88
|
+
## [0.1.0] - 2023-08-20
|
78
89
|
|
79
90
|
Initial release.
|
91
|
+
|
92
|
+
[unreleased]: https://github.com/Chadowo/aniruby/compare/v0.2.2...HEAD
|
93
|
+
[0.2.2]: https://github.com/Chadowo/aniruby/compare/v0.2.1...v0.2.2
|
94
|
+
[0.2.1]: https://github.com/Chadowo/aniruby/compare/v0.2.0...v0.2.1
|
95
|
+
[0.2.0]: https://github.com/Chadowo/aniruby/compare/v0.1.3...v0.2.0
|
96
|
+
[0.1.3]: https://github.com/Chadowo/aniruby/compare/v0.1.2...v0.1.3
|
97
|
+
[0.1.2]: https://github.com/Chadowo/aniruby/compare/v0.1.1...v0.1.2
|
98
|
+
[0.1.1]: https://github.com/Chadowo/aniruby/compare/v0.1.0...v0.1.1
|
99
|
+
[0.1.0]: https://github.com/Chadowo/aniruby/releases/v0.1.0
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# AniRuby
|
2
2
|
|
3
|
-

|
3
|
+
  
|
4
4
|
|
5
|
-
Make sprite animations on Gosu
|
5
|
+
Make sprite animations on Gosu, simply and easily.
|
6
6
|
|
7
7
|
## Summary
|
8
8
|
|
@@ -10,13 +10,15 @@ This library will provide you with a nice n easy interface to do sprite animatio
|
|
10
10
|
on [Gosu](https://www.libgosu.org/), while being as nifty and simple as possible.
|
11
11
|
|
12
12
|
The library is made in pure Ruby with no dependencies at all (except Gosu, of course) so
|
13
|
-
|
13
|
+
it's quite lightweight.
|
14
14
|
|
15
15
|
## Install
|
16
16
|
|
17
17
|
You can install the gem with the following command:
|
18
18
|
|
19
|
-
|
19
|
+
```console
|
20
|
+
gem install aniruby
|
21
|
+
```
|
20
22
|
|
21
23
|
or use it with a bundle:
|
22
24
|
|
@@ -40,8 +42,7 @@ class MyWindow < Gosu::Window
|
|
40
42
|
super(800, 600, false)
|
41
43
|
|
42
44
|
@animation = AniRuby::Animation.new('my_spritesheet.png', 32, 32,
|
43
|
-
false, true
|
44
|
-
0.15)
|
45
|
+
0.15, retro: false, loop: true)
|
45
46
|
end
|
46
47
|
|
47
48
|
def update
|
@@ -92,17 +93,29 @@ have to learn anything new.
|
|
92
93
|
|
93
94
|
Each `Animation` has extra helpful methods, like `pause` & `unpause`, `reset`,
|
94
95
|
`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
|
+
understand, or build the YARD documentation with:
|
96
97
|
|
97
|
-
|
98
|
+
```console
|
99
|
+
rake doc
|
100
|
+
```
|
98
101
|
|
99
102
|
## Development
|
100
103
|
|
104
|
+
### Setup
|
105
|
+
|
101
106
|
First clone this repo locally:
|
102
107
|
|
103
|
-
|
108
|
+
```console
|
109
|
+
git clone https://github.com/Chadowo/aniruby
|
110
|
+
```
|
111
|
+
|
112
|
+
Next you'll need to install the development dependencies of this gem with
|
113
|
+
`bundle install`, Then you can use `rake` to build or test the gem.
|
114
|
+
|
115
|
+
### Testing
|
104
116
|
|
105
|
-
|
117
|
+
[Minitest](https://github.com/minitest/minitest) is used to unit test this gem.
|
118
|
+
To run the tests just call `rake`.
|
106
119
|
|
107
120
|
## Roadmap
|
108
121
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'fileutils'
|
1
|
+
require 'bundler/gem_tasks'
|
3
2
|
require 'minitest/test_task'
|
4
3
|
|
5
4
|
require_relative 'lib/aniruby/version'
|
@@ -8,25 +7,6 @@ Minitest::TestTask.create
|
|
8
7
|
|
9
8
|
task :default => :test
|
10
9
|
|
11
|
-
desc 'Build the gem'
|
12
|
-
task :build do
|
13
|
-
Dir.mkdir('pkg') unless Dir.exist?('pkg')
|
14
|
-
|
15
|
-
sh 'gem build aniruby.gemspec'
|
16
|
-
|
17
|
-
FileUtils.mv("aniruby-#{AniRuby::VERSION}.gem", 'pkg')
|
18
|
-
end
|
19
|
-
|
20
|
-
desc 'Clean the build enviroment'
|
21
|
-
task :clean do
|
22
|
-
FileUtils.rm_rf('pkg')
|
23
|
-
end
|
24
|
-
|
25
|
-
desc 'Push the gem to RubyGems'
|
26
|
-
task :push do
|
27
|
-
sh "gem push pkg/aniruby-#{AniRuby::VERSION}.gem"
|
28
|
-
end
|
29
|
-
|
30
10
|
desc 'Use YARD to generate documentation'
|
31
11
|
task :doc do
|
32
12
|
sh 'yardoc'
|
data/lib/aniruby/animation.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module AniRuby
|
3
2
|
# Has a AniRuby::Frames colletion, with a simple counter to keep track of
|
4
3
|
# current frame plus looping and pausing functionality
|
@@ -6,7 +5,7 @@ module AniRuby
|
|
6
5
|
# @return [AniRuby::Frames] The collection of frames this animation uses
|
7
6
|
attr_accessor :frames
|
8
7
|
# @return [Integer] The current frame index of the animation
|
9
|
-
attr_accessor :
|
8
|
+
attr_accessor :cursor
|
10
9
|
# @return [Boolean] The loop parameter
|
11
10
|
attr_accessor :loop
|
12
11
|
|
@@ -15,32 +14,37 @@ module AniRuby
|
|
15
14
|
# @param spritesheet [String] Path to the spritesheet file
|
16
15
|
# @param frame_w [Integer] The width of each individual frame
|
17
16
|
# @param frame_h [Integer] The height of each individual frame
|
18
|
-
# @param retro [Boolean] If true, the animation will not be interpolated when scaled
|
19
|
-
# @param loop [Boolean] If true, the animation will loop indefinitely
|
20
17
|
# @param durations [Float] The duration of the frames in MS (0.5 is half a second,
|
21
18
|
# 1.0 a second, etc). If there's more than one duration
|
22
19
|
# provided they will be mapped to each frame of the
|
23
20
|
# animation. The default for each frame is 0.1.
|
21
|
+
# If the value is negative it'll default to 0.1.
|
22
|
+
# @param retro [Boolean] If true, the animation will not be interpolated when scaled
|
23
|
+
# @param loop [Boolean] If true, the animation will loop indefinitely
|
24
24
|
#
|
25
25
|
# @return [Animation] A new animation ready to play
|
26
26
|
def initialize(spritesheet,
|
27
27
|
frame_w, frame_h,
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
*durations,
|
29
|
+
retro: false,
|
30
|
+
loop: true)
|
31
31
|
@frame_w = frame_w
|
32
32
|
@frame_h = frame_h
|
33
33
|
|
34
34
|
@loop = loop
|
35
|
-
|
36
|
-
@position = 0
|
37
35
|
@pause = false
|
38
36
|
|
37
|
+
@cursor = 0
|
38
|
+
@step = 1
|
39
|
+
|
39
40
|
@frames = AniRuby::Frames.new(Gosu::Image.load_tiles(spritesheet,
|
40
41
|
@frame_w,
|
41
42
|
@frame_h,
|
42
43
|
retro: retro))
|
43
44
|
|
45
|
+
# Default to 0.1 if the duration is negative
|
46
|
+
durations.map! { |dur| dur.negative? ? 0.1 : dur }
|
47
|
+
|
44
48
|
# TODO: Maybe I could shorten this, adding an extra argument to
|
45
49
|
# AniRuby::Frames
|
46
50
|
if durations.one?
|
@@ -58,19 +62,21 @@ module AniRuby
|
|
58
62
|
#
|
59
63
|
# @return [Integer]
|
60
64
|
def width
|
61
|
-
@frames[@
|
65
|
+
@frames[@cursor].width
|
62
66
|
end
|
63
67
|
|
64
|
-
alias
|
68
|
+
alias w width
|
65
69
|
|
66
70
|
# Get the height of the current frame's image
|
67
71
|
#
|
68
72
|
# @return [Integer]
|
69
73
|
def height
|
70
|
-
@frames[@
|
74
|
+
@frames[@cursor].height
|
71
75
|
end
|
72
76
|
|
73
|
-
alias
|
77
|
+
alias h height
|
78
|
+
|
79
|
+
# @!group Drawing
|
74
80
|
|
75
81
|
# Update the animation, advancing the frame counter. Note that this won't do
|
76
82
|
# do anything if the animation is paused or has finished
|
@@ -78,9 +84,9 @@ module AniRuby
|
|
78
84
|
return unless frame_expired? && !paused?
|
79
85
|
|
80
86
|
if !done?
|
81
|
-
@
|
87
|
+
@cursor += @step
|
82
88
|
elsif done? && @loop
|
83
|
-
@
|
89
|
+
@cursor = 0
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
@@ -94,13 +100,13 @@ module AniRuby
|
|
94
100
|
# @param color [Gosu::Color] The color to usw when drawing
|
95
101
|
# @param mode [:default, :additive] The blending mode
|
96
102
|
#
|
97
|
-
# (see {draw_rot})
|
103
|
+
# (see also {draw_rot})
|
98
104
|
def draw(x, y, z = 0,
|
99
105
|
scale_x = 1,
|
100
106
|
scale_y = 1,
|
101
107
|
color = Gosu::Color::WHITE,
|
102
108
|
mode = :default)
|
103
|
-
frame = @frames[@
|
109
|
+
frame = @frames[@cursor]
|
104
110
|
|
105
111
|
frame.sprite.draw(x, y, z, scale_x, scale_y, color, mode)
|
106
112
|
end
|
@@ -118,7 +124,7 @@ module AniRuby
|
|
118
124
|
# @param color [Gosu::Color] The color to usw when drawing
|
119
125
|
# @param mode [:default, :additive] The blending mode
|
120
126
|
#
|
121
|
-
# (see {draw})
|
127
|
+
# (see also {draw})
|
122
128
|
def draw_rot(x, y, z = 0,
|
123
129
|
angle = 0,
|
124
130
|
center_x = 0.5,
|
@@ -127,14 +133,18 @@ module AniRuby
|
|
127
133
|
scale_y = 1,
|
128
134
|
color = Gosu::Color::WHITE,
|
129
135
|
mode = :default)
|
130
|
-
frame = @frames[@
|
136
|
+
frame = @frames[@cursor]
|
131
137
|
|
132
138
|
frame.sprite.draw_rot(x, y, z, angle, center_x, center_y, scale_x, scale_y, color, mode)
|
133
139
|
end
|
134
140
|
|
141
|
+
# @!endgroup
|
142
|
+
|
143
|
+
# @!group Utility
|
144
|
+
|
135
145
|
# Pause the animation
|
136
146
|
#
|
137
|
-
# (see {resume})
|
147
|
+
# (see also {resume})
|
138
148
|
def pause
|
139
149
|
@pause = true
|
140
150
|
|
@@ -143,7 +153,7 @@ module AniRuby
|
|
143
153
|
|
144
154
|
# Resume the animation
|
145
155
|
#
|
146
|
-
# (see {pause})
|
156
|
+
# (see also {pause})
|
147
157
|
def resume
|
148
158
|
@pause = false
|
149
159
|
|
@@ -152,11 +162,13 @@ module AniRuby
|
|
152
162
|
|
153
163
|
# Set the animation to the beginning frame
|
154
164
|
def reset
|
155
|
-
@
|
165
|
+
@cursor = 0
|
156
166
|
|
157
167
|
self
|
158
168
|
end
|
159
169
|
|
170
|
+
alias reset! reset
|
171
|
+
|
160
172
|
# Set the duration for all frames in the animation
|
161
173
|
#
|
162
174
|
# @param ms [Float] The new duration in milliseconds
|
@@ -171,7 +183,7 @@ module AniRuby
|
|
171
183
|
# @return [Boolean]
|
172
184
|
# @note This method will return true in intervals if the animation loops
|
173
185
|
def done?
|
174
|
-
return true if @
|
186
|
+
return true if @cursor == @frames.count - 1
|
175
187
|
|
176
188
|
false
|
177
189
|
end
|
@@ -189,15 +201,17 @@ module AniRuby
|
|
189
201
|
#
|
190
202
|
# @return [AniRuby::Frame]
|
191
203
|
def current_frame
|
192
|
-
@frames[@
|
204
|
+
@frames[@cursor % @frames.count]
|
193
205
|
end
|
194
206
|
|
207
|
+
# @!endgroup
|
208
|
+
|
195
209
|
# Has the current frame's duration expired?
|
196
210
|
def frame_expired?
|
197
211
|
now = Gosu.milliseconds / 1000.0
|
198
212
|
@last_frame ||= now
|
199
213
|
|
200
|
-
if (now - @last_frame) > @frames[@
|
214
|
+
if (now - @last_frame) > @frames[@cursor].duration
|
201
215
|
@last_frame = now
|
202
216
|
end
|
203
217
|
end
|
data/lib/aniruby/frame.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module AniRuby
|
3
2
|
# A frame has a sprite that's Gosu::Image and a duration specified in
|
4
3
|
# milliseconds
|
@@ -12,8 +11,8 @@ module AniRuby
|
|
12
11
|
# @return [Integer]
|
13
12
|
attr_reader :width, :height
|
14
13
|
|
15
|
-
alias
|
16
|
-
alias
|
14
|
+
alias w width
|
15
|
+
alias h height
|
17
16
|
|
18
17
|
# Create a new frame
|
19
18
|
#
|
data/lib/aniruby/frames.rb
CHANGED
data/lib/aniruby/version.rb
CHANGED
data/lib/aniruby.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.2.
|
4
|
+
version: 0.2.2
|
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-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 13.0.0
|
69
69
|
description: |
|
70
|
-
Library for painless sprite animations on Gosu, with
|
70
|
+
Library for painless sprite animations on Gosu, with an easy
|
71
71
|
and nifty API, made in pure Ruby with no dependencies at all!
|
72
72
|
email:
|
73
73
|
executables: []
|
@@ -87,7 +87,11 @@ files:
|
|
87
87
|
homepage: https://github.com/Chadowo/aniruby
|
88
88
|
licenses:
|
89
89
|
- MIT
|
90
|
-
metadata:
|
90
|
+
metadata:
|
91
|
+
bug_tracker_uri: https://github.com/Chadowo/aniruby/issues
|
92
|
+
changelog_uri: https://github.com/Chadowo/aniruby/blob/main/CHANGELOG.md
|
93
|
+
homepage_uri: https://github.com/Chadowo/aniruby
|
94
|
+
source_code_uri: https://github.com/Chadowo/aniruby
|
91
95
|
post_install_message:
|
92
96
|
rdoc_options: []
|
93
97
|
require_paths:
|
@@ -104,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
108
|
version: '0'
|
105
109
|
requirements:
|
106
110
|
- Gosu installed and working
|
107
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.5.3
|
108
112
|
signing_key:
|
109
113
|
specification_version: 4
|
110
|
-
summary: Make sprite animations on Gosu
|
114
|
+
summary: Make sprite animations on Gosu, simply and easily
|
111
115
|
test_files: []
|