Explain it.
I assume these are incomplete snippets of your actual code, since the code, as shown, calls draw_rect with @x and @y set to nil, throwing out the undefined '-' method to exclude nil: nilClass, because you cannot subtract anything from scratch.)
, ,
, , Player.draw .
? Chingu
GameObjects, GameObject.create
GameObject.new.
(http://rdoc.info/projects/ippa/chingu)
Chingu:: GameObject
. , , , , . ( !). , . GameObject.create() new() Chingu "game_object" -list /.
Chingu:: BasicGameObject
() vs create() GameObject BasicGameObject.
. ...
, Player.draw Chingu, : draw_rect ! , Ruby :
in draw_rect': undefined method x ' [99, 101, 101, 101, 101, 99, 101, 101]: (NoMethodError)
... , draw_rect, , ? .
(http://github.com/ippa/chingu/blob/master/lib/chingu/helpers/gfx.rb)
def draw_rect(rect, color, zorder)
$window.draw_line(rect.x, rect.y, color, rect.right, rect.y, color, zorder)
$window.draw_line(rect.right, rect.y, color, rect.right, rect.bottom, color, zorder)
$window.draw_line(rect.right, rect.bottom, color, rect.x, rect.bottom, color, zorder)
$window.draw_line(rect.x, rect.bottom, color, rect.x, rect.y, color, zorder)
end
, . draw_rect , Rectangle, . :
(http://rdoc.info/projects/ippa/chingu)
Chingu::Rect
Constructor Details
- (Rect) initialize(*argv)
Create a new Rect, attempting to extract its own information from the
given arguments.
The arguments must fall into one of these cases:
- 4 integers +(x, y, w, h)+.
- 1 Rect or Array containing 4 integers +([x, y, w, h])+.
- 2 Arrays containing 2 integers each +([x,y], [w,h])+.
- 1 object with a +rect+ attribute which is a valid Rect object.
All rect core attributes (x,y,w,h) must be integers.
Rect,
draw_rect Rect .
, . -
require 'rubygems'
require 'chingu'
class Game < Chingu::Window
def initialize
super
puts "initializing player..."
@player = Player.create
end
end
class Player < Chingu::BasicGameObject
def initialize(options = {})
super
@x = 100
@y = 100
@rect = Chingu::Rect.new(@x, @y, 10, 10)
@c = Gosu::Color.new(0xffff0000)
end
def draw
puts "inside draw"
puts @x, @y
$window.draw_rect(@rect, @c, 1)
end
end
Game.new.show
100 100.
, .
~