forked from rubymotion-community/Joybox
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rubymotion-community#59 from meganemura/add-layer-…
…gradient Adds: => `Joybox::Core::LayerGradient`
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Joybox | ||
module Core | ||
|
||
class LayerGradient < CCLayerGradient | ||
include TouchEvent | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Joybox | ||
module Core | ||
|
||
class LayerGradient < CCLayerGradient | ||
|
||
include MouseEvent | ||
include KeyboardEvent | ||
include GestureEvent | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Joybox | ||
module Core | ||
|
||
class LayerGradient < CCLayerGradient | ||
|
||
include Joybox::Common | ||
|
||
def self.scene | ||
define_singleton_method(:scene) do |options = {}| | ||
scene = CCScene.new | ||
layer = self.new(options) | ||
scene << layer | ||
end | ||
end | ||
|
||
def self.defaults | ||
{ | ||
vector: [0, -1] | ||
} | ||
end | ||
|
||
def initialize(options = {}) | ||
options = self.class.defaults.merge(options) | ||
|
||
layer = self.initWithColor(options[:start], | ||
fadingTo: options[:end], | ||
alongVector: options[:vector]) | ||
|
||
layer.position = options[:position] if options[:position] | ||
end | ||
|
||
def onEnter | ||
super | ||
on_enter if defined? (on_enter) | ||
end | ||
|
||
def onExit | ||
super | ||
on_exit if defined? (on_exit) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
describe Joybox::Core::LayerGradient do | ||
|
||
describe "LayerGradient.new" do | ||
it "should initialize" do | ||
layer = Joybox::Core::LayerGradient.new( | ||
start: [1, 2, 3, 4], | ||
end: [1, 2, 3, 4], | ||
vector: [1, 2]) | ||
layer.should.not == nil | ||
layer.visible.should == true | ||
layer.class.should == Joybox::Core::LayerGradient | ||
end | ||
end | ||
|
||
describe "LayerGradient.scene" do | ||
it "should define singleton method and return CCScene with LayerGradient" do | ||
Joybox::Core::LayerGradient.scene | ||
scene = Joybox::Core::LayerGradient.scene(start: [1, 2, 3, 4], end: [5, 6, 7, 8], vector: [1, 2]) | ||
scene.class.should == CCScene | ||
scene.children.first.class.should == Joybox::Core::LayerGradient | ||
end | ||
end | ||
|
||
end |