Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / gosu shapes color and design
- - By ryuken Date 2013-02-24 13:39
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?

also  how do you specify the color to these shapes?

I quickly came up with this code (mind you, i am newbie and learning ruby and gosu)

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
DemoWindow.new.show

any thoughts? :)
Parent - - By rremedio Date 2013-02-24 13:41
I suppose you need values for x1, x2, etc...
Parent - - By ryuken Date 2013-02-24 15:16
Yes, I have placed values into that but have to work on the color and also if i am right about placing the methods in draw method()?  or that is wrong?
Parent - By rremedio Date 2013-02-24 15:41
I can't tell you about the best way to work with colors in that case cause I've never really used draw_shape methods. I think it will depend on the effects you want (take a look here http://www.libgosu.org/rdoc/Gosu/Color.html). But the way you coded worked here and yes, drawing methods (be them for shapes or sprites) should go into the main window draw method.
Parent - - By BlueScope Date 2013-02-24 16:37 Edited 2013-02-24 16:43
Assigning values seems to be your problem... This should work perfectly:

require 'rubygems'
require 'gosu'

class DemoWindow < Gosu::Window
 
  def initialize
    super(640, 400, false)
  end

  def draw
    x = 300
    y = 200
    size = 120
    draw_quad(x-size, y-size, 0xffff8888, x+size, y-size, 0xffffffff, x-size, y+size, 0xffffffff, x+size, y+size, 0xffffffff, 0)
  end
 
end

DemoWindow.new.show


Also, note that something like z=0 isn't meant to be in a method call like you have it in your draw_triangle or draw_line calls - you just would write 0 instead (or leave it out entirely). the z=0 means that if no value is passed, it will default to 0.

As for update and draw, it really doesn't matter in which hyou call your methods, however for easyness and understanding, putting draw commands in draw and changing of variables and the like in update makes more sense.
As a side note, draw is called before update. I'm mentioning this as it did cause problems for me in the past where I assumed that it was the other way round, but it shouldn't matter in general.

Last but not least colors... you basically assign them in this way:
0x[aa][rr][gg][bb]
All those two-letter variables have to be a hex-value from 0 to 255, so for example, white is 0xffffffff, blackis 0xff000000, and semi-transparent red is 0x80ff0000.
Parent - - By ryuken Date 2013-02-24 17:15
Thanks, the logic for x-size and x+size done it. One more question, is it possible to change the background color of gosu window? or we have only option of image to replace that?

I mean changing color via hex value?
Parent - - By erisdiscord Date 2013-02-24 17:42
There's no way to change it, but you can always draw_quad a shape that fills the whole window. Pass -Float::INFINITY for z to make sure it's drawn below everything.
Parent - By ryuken Date 2013-02-24 18:21
Thanks :)
Up Topic Gosu / Gosu Exchange / gosu shapes color and design

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill