aniruby 0.1.2 → 0.2.0
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 +40 -5
- data/README.md +53 -14
- data/Rakefile +2 -2
- data/lib/aniruby/animation.rb +39 -22
- data/lib/aniruby/frame.rb +22 -6
- data/lib/aniruby/frames.rb +3 -1
- 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
@@ -5,24 +5,59 @@ 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.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
|
+
|
33
|
+
## 0.1.3 - 2023-08-22
|
34
|
+
|
35
|
+
### Fixed
|
36
|
+
|
37
|
+
- Undefined method error in animation, when using `size` on `AniRuby::Frames`, now
|
38
|
+
use `Enumerable#count` instead.
|
39
|
+
|
40
|
+
### Changed
|
41
|
+
|
42
|
+
- The way milliseconds are used as duration, before you'll have to use whole numbers
|
43
|
+
(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
44
|
|
10
45
|
## 0.1.2 - 2023-08-20
|
11
46
|
|
12
47
|
### Changed
|
13
48
|
|
14
|
-
- Downcased the gem name in the gemspec
|
49
|
+
- Downcased the gem name in the gemspec.
|
15
50
|
|
16
51
|
## 0.1.1 - 2023-08-20
|
17
52
|
|
18
53
|
### Added
|
19
54
|
|
20
|
-
- Add .yardopts to included files
|
55
|
+
- Add .yardopts to included files.
|
21
56
|
|
22
57
|
### Fixed
|
23
58
|
|
24
|
-
- Required ruby not being used correctly in gemspec
|
59
|
+
- Required ruby not being used correctly in gemspec.
|
25
60
|
|
26
61
|
## 0.1.0 - 2023-08-20
|
27
62
|
|
28
|
-
Initial release
|
63
|
+
Initial release.
|
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# AniRuby
|
2
2
|
|
3
|
+

|
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,23 +60,58 @@ 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
|
+

|
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
|
+

|
73
|
+
|
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
|
+
|
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
|
+

|
82
|
+
|
83
|
+
Ain't that nice?
|
84
|
+
|
85
|
+
### Drawing
|
86
|
+
|
87
|
+
You can draw an animation like any other `Gosu::Image`! An 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
|
|
78
|
-
[MIT](LICENSE)
|
117
|
+
This library is licensed under the [MIT](LICENSE) license.
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
2
|
require 'fileutils'
|
3
|
-
require
|
3
|
+
require 'minitest/test_task'
|
4
4
|
|
5
5
|
require_relative 'lib/aniruby/version'
|
6
6
|
|
7
7
|
Minitest::TestTask.create
|
8
8
|
|
9
|
-
task :default => :
|
9
|
+
task :default => :test
|
10
10
|
|
11
11
|
desc 'Build the gem'
|
12
12
|
task :build do
|
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
|
@@ -17,20 +17,23 @@ 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
|
-
# frames with no specified duration will default to 100
|
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.
|
25
24
|
#
|
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
|
-
# @param ms [
|
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,16 +189,16 @@ 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?
|
180
197
|
def frame_expired?
|
181
|
-
now = Gosu.milliseconds
|
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
@@ -1,16 +1,32 @@
|
|
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
|
-
|
6
|
+
# @return [Float]
|
7
|
+
attr_accessor :duration
|
7
8
|
|
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
|
17
|
+
|
18
|
+
# Create a new frame
|
19
|
+
#
|
20
|
+
# @param sprite [Gosu::Image]
|
21
|
+
# @param duration [Float]
|
22
|
+
#
|
23
|
+
# @return [Frame]
|
24
|
+
def initialize(sprite, duration = 0.1)
|
9
25
|
@sprite = sprite
|
10
26
|
@duration = duration
|
11
27
|
|
12
|
-
@
|
13
|
-
@
|
28
|
+
@width = @sprite.width
|
29
|
+
@height = @sprite.height
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|
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.
|
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
|