rubydraw 0.1.4 → 0.1.5
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 +4 -1
- data/examples/media/noise.ogg +0 -0
- data/examples/sound_ex.rb +5 -1
- data/lib/rubydraw/image.rb +2 -7
- data/lib/rubydraw/sound.rb +40 -10
- data/lib/rubydraw.rb +4 -1
- metadata +5 -4
data/README
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
Rubydraw is a high level game/graphics library, like Gosu or Rubygame, and is written in Ruby.
|
2
|
-
Its only dependency is ruby-sdl-ffi, which it uses to access SDL functions.
|
2
|
+
Its only dependency is ruby-sdl-ffi, which it uses to access SDL functions. Also, thanks,
|
3
|
+
Rubygame, for documenting your code (which, completely by coninsidence, also uses ruby-sdl-ffi),
|
4
|
+
otherwise I wouldn't have the slightest idea on how to use the base library's undocumented code!
|
5
|
+
You have been very helpful. :)
|
3
6
|
–––––
|
4
7
|
NOTE: I can't get +ruby-sdl-ffi+ (the library Rubydraw uses to access SDL) to work with +Ruby
|
5
8
|
1.9.2+, so I don't know if it even does. If it does work, and/or you know how to make it work,
|
Binary file
|
data/examples/sound_ex.rb
CHANGED
@@ -5,11 +5,15 @@ class MyWindow < Rubydraw::Window
|
|
5
5
|
def initialize
|
6
6
|
super(300, 300)
|
7
7
|
@sound = Rubydraw::Sound.new("media/hooray.ogg")
|
8
|
+
@sound2 = Rubydraw::Sound.new("media/noise.o.ogg")
|
8
9
|
whenever Rubydraw::Events::QuitRequest do
|
9
10
|
close
|
10
11
|
end
|
11
12
|
whenever Rubydraw::Events::KeyPressed do
|
12
|
-
@sound.play
|
13
|
+
@sound.play if @sound.stopped?
|
14
|
+
end
|
15
|
+
whenever Rubydraw::Events::FocusLoss do
|
16
|
+
@sound2.play if @sound2.stopped?
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
data/lib/rubydraw/image.rb
CHANGED
@@ -15,7 +15,7 @@ module Rubydraw
|
|
15
15
|
if @sdl_image.pointer.null?
|
16
16
|
# SDL couln't load the image; usually happens because it doesn't
|
17
17
|
# exist.
|
18
|
-
raise Rubydraw::SDLError "Failed to load image
|
18
|
+
raise Rubydraw::SDLError "Failed to load image: #{SDL.GetError}"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -28,6 +28,7 @@ module Rubydraw
|
|
28
28
|
source_rect = SDL::Rect.new([0, 0, width, height])
|
29
29
|
blit_rect = SDL::Rect.new([position.x, position.y, window.width, window.height])
|
30
30
|
SDL::BlitSurface(@sdl_image, source_rect, window.sdl_surface, blit_rect)
|
31
|
+
self
|
31
32
|
end
|
32
33
|
|
33
34
|
# Returns the image width
|
@@ -39,11 +40,5 @@ module Rubydraw
|
|
39
40
|
def height
|
40
41
|
@sdl_image.h
|
41
42
|
end
|
42
|
-
|
43
|
-
# Returns the SDL image that was created in Image#initialize.
|
44
|
-
# Rubydraw::Window uses this to draw this Image instance.
|
45
|
-
def sdl_image
|
46
|
-
@sdl_image
|
47
|
-
end
|
48
43
|
end
|
49
44
|
end
|
data/lib/rubydraw/sound.rb
CHANGED
@@ -8,6 +8,8 @@ module Rubydraw
|
|
8
8
|
# Rubydraw::Sound#play: Plays the sound. *Note*: this method exits
|
9
9
|
# immediatley; it doesn't wait until the sound is finished.
|
10
10
|
class Sound
|
11
|
+
# Used to specify the volume (from 0 to 1) when this sound is played.
|
12
|
+
# Set at 1 by default
|
11
13
|
attr_accessor(:volume)
|
12
14
|
# Create a new sound with the given file path. Raise an SDLError if for
|
13
15
|
# some reason it couln't load the sound.
|
@@ -21,25 +23,53 @@ module Rubydraw
|
|
21
23
|
if @sdl_sound.pointer.null?
|
22
24
|
raise SDLError "Failed to load sound from: #{full_path} because '#{SDL.GetError}'"
|
23
25
|
end
|
26
|
+
# The default volume. Can be changed with Sound's volume arrtibute.
|
24
27
|
@volume = 1
|
25
|
-
|
28
|
+
# Allocate a new SDL channel all for this sound to use.
|
29
|
+
@channel = SDL::Mixer.AllocateChannels(SDL::Mixer.AllocateChannels(-1) + 1) - 1
|
26
30
|
end
|
27
31
|
|
28
|
-
# Play this sound,
|
32
|
+
# Play this sound, but don't restart it if it's already playing.
|
29
33
|
def play
|
30
|
-
SDL::Mixer.HaltChannel(@channel)
|
31
|
-
@channel = SDL::Mixer.GroupAvailable(-1)
|
32
|
-
if @channel == -1
|
33
|
-
SDL::Mixer.AllocateChannel(SDL::Mixer.AllocateChannel(-1) + 1)
|
34
|
-
@channel = SDL::Mixer.GroupAvailible
|
35
|
-
end
|
36
34
|
SDL::Mixer.Volume(@channel, (SDL::Mixer::MAX_VOLUME * @volume).to_i)
|
37
35
|
result = SDL::Mixer.PlayChannelTimed(@channel, @sdl_sound, 0, -1)
|
38
36
|
raise(SDLError, "Failed to play sound: #{SDL.GetError}") if result == -1
|
39
37
|
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Pause the sound so it can be resumed later.
|
41
|
+
def pause
|
42
|
+
SDL::Mixer.Pause(@channel)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
# Stop the sound. Unlike pause because Sound#play will start from the
|
47
|
+
# beginning afterward.
|
48
|
+
def stop
|
49
|
+
SDL::Mixer.HaltChannel(@channel)
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Resume the sound from where it was paused.
|
54
|
+
def resume
|
55
|
+
SDL::Mixer.Resume(@channel)
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# Returns whether or not this sound is paused.
|
61
|
+
def paused?
|
62
|
+
SDL::Mixer.Paused(@channel) == 1
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns whether or not this sound is playing.
|
66
|
+
def playing?
|
67
|
+
(SDL::Mixer.Playing(@channel) == 1) and not paused?
|
68
|
+
end
|
40
69
|
|
41
|
-
|
42
|
-
|
70
|
+
# Returns whether or not this sound is stopped.
|
71
|
+
def stopped?
|
72
|
+
not playing?
|
43
73
|
end
|
44
74
|
end
|
45
75
|
end
|
data/lib/rubydraw.rb
CHANGED
@@ -14,7 +14,10 @@ files = %w[
|
|
14
14
|
files.each {|f| require("rubydraw/" + f)}
|
15
15
|
|
16
16
|
# Rubydraw is a high level game/graphics library, like Gosu or Rubygame, and is written completely
|
17
|
-
# in Ruby. Its only dependency is ruby-sdl-ffi, which it uses to access SDL functions.
|
17
|
+
# in Ruby. Its only dependency is ruby-sdl-ffi, which it uses to access SDL functions. Also, thanks,
|
18
|
+
# Rubygame, for documenting your code (which, completely by coninsidence, also uses ruby-sdl-ffi),
|
19
|
+
# otherwise I wouldn't have the slightest idea on how to use the base library's undocumented code!
|
20
|
+
# You have been very helpful. :)
|
18
21
|
#
|
19
22
|
# NOTE: I can't get +ruby-sdl-ffi+ (the library Rubydraw uses to access SDL) to work with +Ruby
|
20
23
|
# 1.9.2,+ so I don't know if it even does. If it does work, and/or you know how to make it work,
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydraw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- J. Wostenberg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-17 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- examples/sound_ex.rb
|
63
63
|
- examples/media/bug.png
|
64
64
|
- examples/media/hooray.ogg
|
65
|
+
- examples/media/noise.ogg
|
65
66
|
has_rdoc: true
|
66
67
|
homepage: https://github.com/awostenberg/rubydraw
|
67
68
|
licenses: []
|