Reputation: 45
I am trying to make some simple shapes in gosu (ruby). I am finding it difficult where to call the functions. Is it update method or the draw method.
require 'rubygems'
require 'gosu'
class DemoWindow < Gosu::Window
def initialize
super(640, 400, false)
end
def draw
draw_quad(x-size, y-size, 0xffffffff, x+size, y-size, 0xffffffff, x-size, y+size, 0xffffffff, x+size, y+size, 0xffffffff, 0)
draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default)
draw_line(x1, y1, c1, x2, y2, c2, z=0, mode=:default)
end
end
Please take a look and let me know if this is the right way to create shapes.
Upvotes: 1
Views: 6992
Reputation: 305
From what I have noticed that you do not have update method therefore it is not rendering
class DemoWindow < Gosu::Window
def initialize
super(640, 400, false)
end
def update
end
def draw
draw_quad(x-size, y-size, 0xffffffff, x+size, y-size, 0xffffffff, x-size, y+size, 0xffffffff, x+size, y+size, 0xffffffff, 0)
draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default)
draw_line(x1, y1, c1, x2, y2, c2, z=0, mode=:default)
end
Upvotes: 0
Reputation: 354
From what I'm seeing what you've got should work.
One thing I've noticed about Gosu is that when it first starts up it calls the draw method before it calls the update function. What that means is if you have (not including the shape functions you're using) any images you are going to draw to the screen that you only have defined coordinates for in the update method the program won't work. You've got to define their x and y values with some preliminary location in the draw method first.
This probably won't help you but I thought I'd contribute it on the off chance it might.
Upvotes: 2