Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / How to clear image in main window?
- - By zhzhussupovkz Date 2013-10-14 18:18
Hello world! I need help! I read Gosu documentation, but not found method for delete images from window:
For example:

#class Cheese
class Cheese

  def initialize window, x, y
    @image = Gosu::Image.new(window, "images/cheese.png", false)
    @x, @y = x, y
  end

  #draw cheese
  def draw
    @image.draw(@x, @y, 1)
  end

  def delete
    #what I write here for delete image? In Gosu::Image documentation i not found answer for my question
  end

end

Thanks for all, and sorry for my English!
Parent - - By EdwinOdesseiron Date 2013-10-14 19:16
@image = nil will "delete" the image, but that will cause problems when drawing. You could change your draw to @image.draw(@x,@y,1) if @image != nil.
Parent - By zhzhussupovkz Date 2013-10-16 06:54
Thanks for your answer!
Parent - - By RunnerPack Date 2013-10-14 20:05
I think you might be confused about how Gosu works... The window isn't a persistent canvas you have to manage on your own. The Window#draw method is called periodically, and everything you tell it to draw within that method is drawn on a fresh, blank surface. If you want an image to stay on the screen, you just have to tell Gosu to draw it. If you don't want it to be visible, don't draw it. Looking at the examples should make it clear.

Also, for your above code to work, you'll have to call Cheese#draw (which means: "the draw method of an instance of the Cheese class") within your Window's draw method. When you update the Cheese instance's x and y coordinates, it will move to the new position on the screen automatically.
Parent - - By zhzhussupovkz Date 2013-10-16 06:54
Thank you very match. I'm novice in game development
Parent - - By EdwinOdesseiron Date 2013-10-16 15:17
We've all been :)
Parent - - By RunnerPack Date 2013-10-17 01:44
Some of us still are...  -_-' ' '
Parent - By ml Date 2013-10-17 05:51
lol I'm still a novice too!
Up Topic Gosu / Gosu Exchange / How to clear image in main window?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill