rubymotion-community / Joybox

Cocos2D & Box2D Wrapper for Ruby Motion - Currently out of date an unmaintained :-(
MIT License
280 stars 37 forks source link

No run_action method for Core::Layer #47

Closed n-studio closed 11 years ago

n-studio commented 11 years ago

Hi! I can't access to run_action method with Core::Layer

Error message: layer.rb:23:inonEnter': undefined method run_action' for #<MyLayer:0xc154ba0> (NoMethodError)

my full code:

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @director = Joybox::Configuration.setup do
      director display_stats: true
    end

    @navigation_controller = UINavigationController.alloc.initWithRootViewController(@director)
    @navigation_controller.navigationBarHidden = true

    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @window.setRootViewController(@navigation_controller)
    @window.makeKeyAndVisible

    @director.runWithScene(MyScene.new)

    true
  end

  def applicationWillResignActive(app)
    @director.pause if @navigation_controller.visibleViewController == @director
  end

  def applicationDidBecomeActive(app)
    @director.resume if @navigation_controller.visibleViewController == @director
  end

  def applicationDidEnterBackground(app)
    @director.stop_animation if @navigation_controller.visibleViewController == @director
  end

  def applicationWillEnterForeground(app)
    @director.start_animation if @navigation_controller.visibleViewController == @director
  end

  def applicationWillTerminate(app)
    @director.end
  end

  def applicationDidReceiveMemoryWarning(app)
    @director.purge_cached_data
  end

  def applicationSignificantTimeChange(app)
    @director.set_next_delta_time_zero true
  end
end

class MyScene < Joybox::Core::Scene
  def on_enter
    layer = MyLayer.new
    self << layer
  end
end

class MyLayer < Joybox::Core::Layer
  def on_enter
    self.run_action(Move.by)
  end
end

If I use CCLayer instead Core::Layer, it doesn't crash.

class MyLayer < CCLayer
  def onEnter
    super
    runAction(Move.by)
  end
end
NSCoder commented 11 years ago

Hello!

Thanks for the report! In the version 1.0.0 (The latest version of the gem) the run_action method is not supported on Layers or Scenes, only on Sprites.

The repository version (That will be released soon as gem :)) now supports the run_action on layers and scenes, there are some workarounds that I hope can make your code work properly:

1) Using Core::Layer call runAction instead of run_action (I haven't tested it yet but i think it should be no problem)

2) Download the beta version of the gem: http://cl.ly/QMX4 and install it using gem install joybox-1.1.0b.gem (And configure your project to use it)

3) Using a Gemfile configure the gem to be downloaded from the repository:

gem 'joybox', :git => 'git@github.com:rubymotion/Joybox.git'

I hope it helps! JK

NSCoder commented 11 years ago

Finally fixed in 1.1.0 :)