ippa / chingu

OpenGL accelerated 2D game framework for Ruby
http://ippa.se/chingu
GNU Lesser General Public License v2.1
309 stars 66 forks source link

Parallax and Viewpoint #3

Closed HakubJozak closed 14 years ago

HakubJozak commented 14 years ago

There is a problem when using Parallax and Viewpoint together since Parallax is GameObject but does not have @image set and therefor the draw_relative method fails:

 chingu-0.7.5/lib/chingu/game_object.rb:155:in `draw_relative': undefined method      `draw_rot' for nil:NilClass (NoMethodError)

Minimal code reproducing the issue is:

class Flying < Chingu::GameState

   trait :viewport

  def initialize(options = {})
    super
     @parallax = Chingu::Parallax.create(:x => 0, :y => 0, :rotation_center => :top_left)
  end
end

class Game < Chingu::Window
  def initialize
    switch_game_state(Flying)
  end
end

Is there something wrong with my understanding or is it an issue? AFAIK it is not fixed in master branch but I am willing to consult it and commit a fix, please let me know.

thanks

Jakub

ippa commented 14 years ago

class Parallax needs to override draw_rot() it gets from GameObject in a simular way it overrides draw(). Two things though:

1) There might be a connection to be made between a viewport and a parallax.. they do share the idea of having a camera/viewport move and change what's displayed accordingly. Maybe there's a really good way of intergrating them.

2) viewport-trait now depends on GameObject#draw_relative to do it's thing. This could become obsolete by using Gosu's new transformations. Then Chingu could wrap up the ordinary draw-calls in translate (x, y, &drawing_code)-block. There's a patch contributed for this but there's a crash to fix before it can be merged.

HakubJozak commented 14 years ago

ad 1) good point, let's think about it ... maybe thinking about class Camera would be a good start

ad 2) different uses of draw_* overloading makes Chingu a little bit harder to extend; I think Parallax should not really be a GameObject, rather BasicGameObject since it does not really need most of the stuff

...I am not working with Parallax for now, so I withdraw my fix offer ;] ... the #draw should become #draw_relative and taky @x,@y into account which it now doesn't. For anyone fixing it, good luck!

ippa commented 14 years ago

The translate patch is not active in master, so this should be a non-issue next gemrelease.