rmagick-sprite 0.0.6 → 0.0.7
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.
- data/README.md +53 -11
- data/VERSION +1 -1
- data/lib/rmagick-sprite.rb +2 -2
- data/lib/rmagick-sprite/action.rb +3 -2
- data/rmagick-sprite.gemspec +2 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -1,13 +1,39 @@
|
|
1
1
|
# RMagick-Sprite
|
2
2
|
|
3
|
+
## Description
|
4
|
+
|
5
|
+
`rmagick-sprite` allows you to easily slice up a spritesheet into `Magick::Image` instances.
|
6
|
+
|
7
|
+
The thought is that a spreadsheet contains many of a character's actions (standing, walking, jumping, etc..) which
|
8
|
+
consist of many frames.
|
9
|
+
|
10
|
+
This gem provides a DSL for defining those actions and the size/location of each frame on the spritesheet.
|
11
|
+
|
12
|
+
Then, you are free to use these images in your favorite game library, save each frame as separate images, or
|
13
|
+
even save each action as an animated GIF.
|
14
|
+
|
15
|
+
## Install
|
16
|
+
|
17
|
+
### Bundler: `gem 'rmagick-sprite'`
|
18
|
+
|
19
|
+
### RubyGems: `gem install rmagick-sprite`
|
20
|
+
|
3
21
|
## Example
|
4
22
|
|
23
|
+
### Example Spritesheet
|
24
|
+
<hr/ >
|
25
|
+
|
5
26
|
In this example, I have one character printed on one spritesheet with only one line of
|
6
27
|
evenly spaced/sized sprites.
|
7
28
|
|
8
29
|
Here it is: 
|
9
30
|
|
31
|
+
### Declaration
|
32
|
+
<hr/ >
|
33
|
+
|
10
34
|
```ruby
|
35
|
+
require 'rmagick-sprite'
|
36
|
+
|
11
37
|
sprite = Sprite.new do
|
12
38
|
filename 'foo/bar/character_spritesheet.png'
|
13
39
|
|
@@ -21,7 +47,7 @@ sprite = Sprite.new do
|
|
21
47
|
frame x: 16 * 1 # Frame 1
|
22
48
|
# x: 0, y: 0 is the top-left corner..
|
23
49
|
# I'm lazy, so I'm just taking the default_frame_options width and multiplying it by the
|
24
|
-
# frame
|
50
|
+
# frame's offset to calculate the x coordinate.
|
25
51
|
end
|
26
52
|
|
27
53
|
walking do
|
@@ -38,27 +64,43 @@ sprite = Sprite.new do
|
|
38
64
|
frame x: 16 * 4 # Frame 4
|
39
65
|
end
|
40
66
|
end
|
67
|
+
```
|
41
68
|
|
42
|
-
|
43
|
-
|
69
|
+
### Enumeration
|
70
|
+
<hr/ >
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# The :standing action only has one frame, so next_image will loop over the same frame on each call
|
74
|
+
p sprite.next_image # => Second Image (Magick::Image) - Note that this is the same as: sprite.next_frame.image
|
44
75
|
p sprite.next_image # => Second Image
|
45
76
|
|
46
77
|
sprite.action = :walking
|
47
78
|
|
48
|
-
# Here, we loop through the walking animation.. pump these images right into Gosu or your favorite gaming library
|
49
|
-
p sprite.next_image # =>
|
50
|
-
p sprite.next_image # =>
|
51
|
-
p sprite.next_image # =>
|
52
|
-
p sprite.next_image # =>
|
53
|
-
p sprite.next_image # =>
|
79
|
+
# Here, we loop through the :walking animation.. pump these images right into Gosu or your favorite gaming library
|
80
|
+
p sprite.next_image # => Image 3 - Frame 1
|
81
|
+
p sprite.next_image # => Image 4 - Frame 2
|
82
|
+
p sprite.next_image # => Image 5 - Frame 3
|
83
|
+
p sprite.next_image # => Image 4 - Frame 4
|
84
|
+
p sprite.next_image # => Image 3 - Frame 1
|
85
|
+
```
|
86
|
+
|
87
|
+
### Saving Frames and Actions
|
88
|
+
<hr/ >
|
54
89
|
|
55
|
-
|
90
|
+
#### Save each action's frame as a separate image
|
91
|
+
|
92
|
+
```ruby
|
56
93
|
sprite.actions.each do |action_name, action|
|
57
94
|
action.frames.each_with_index do |frame, index|
|
58
95
|
frame.image.write "foo/bar/#{action_name}_#{index}.png"
|
59
96
|
end
|
60
97
|
end
|
98
|
+
```
|
61
99
|
|
62
|
-
|
100
|
+
#### Saving an action as a gif
|
101
|
+
|
102
|
+
> Note: This looks a bit wonky with transparent backgrounds.
|
103
|
+
|
104
|
+
```ruby
|
63
105
|
sprite.actions[:running].write 'foo/bar/running.gif'
|
64
106
|
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/rmagick-sprite.rb
CHANGED
@@ -65,13 +65,13 @@ class Sprite
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def action
|
68
|
-
@action ||= @actions[@default_action]
|
68
|
+
@action ||= @actions[@default_action || :default]
|
69
69
|
end
|
70
70
|
|
71
71
|
def add_action(name, options={}, &blk)
|
72
72
|
raise 'options must be a Hash' unless options.respond_to?(:to_hash) || options.respond_to?(:to_h)
|
73
73
|
options = options.to_hash rescue options.to_h
|
74
|
-
options = { sprite: self }.merge(@default_action_options).merge(options)
|
74
|
+
options = { sprite: self, name: name }.merge(@default_action_options).merge(options)
|
75
75
|
|
76
76
|
@actions[name] = Action.new(options, &blk)
|
77
77
|
end
|
@@ -7,17 +7,18 @@ class Sprite
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_reader :sprite, :frames
|
10
|
+
attr_reader :sprite, :frames, :name
|
11
11
|
attr_accessor :current_index
|
12
12
|
|
13
13
|
def initialize(options, &blk)
|
14
14
|
raise 'options must be a Hash' unless options.respond_to?(:to_hash) || options.respond_to?(:to_h)
|
15
15
|
options = options.to_hash rescue options.to_h
|
16
16
|
|
17
|
+
raise 'options[:name] must be given' if options[:name].nil?
|
17
18
|
raise 'options[:sprite] must be given' if options[:sprite].nil?
|
18
19
|
raise 'options[:sprite] must be a Sprite' unless options[:sprite].instance_of?(Sprite)
|
19
20
|
|
20
|
-
@sprite = options
|
21
|
+
@sprite, @name = options.values_at(:sprite, :name)
|
21
22
|
@current_index, @frames = 0, []
|
22
23
|
|
23
24
|
DSL.call(self, &blk)
|
data/rmagick-sprite.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "rmagick-sprite"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ryan Scott Lewis"]
|
9
|
-
s.date = "2012-11-
|
9
|
+
s.date = "2012-11-14"
|
10
10
|
s.description = "Encapsulates a \"Sprite\" in RMagick."
|
11
11
|
s.email = "ryan@rynet.us"
|
12
12
|
s.files = [".gitignore", ".rvmrc", "Gemfile", "Gemfile.lock", "README.md", "Rakefile", "VERSION", "lib/rmagick-sprite.rb", "lib/rmagick-sprite/action.rb", "lib/rmagick-sprite/frame.rb", "rmagick-sprite.gemspec"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmagick-sprite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rmagick
|
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash:
|
93
|
+
hash: 2005499775495730886
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|