Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Clickable image?
- - By hans_soleil Date 2014-01-30 15:02
I want to make an on-screen button which can only be clicked on a non-transparent pixel. Does anyone know how?
Parent - - By jahmaican Date 2014-01-30 15:37
You mind using texplay? Here's a quick example:

require 'gosu'
require 'texplay'
include Gosu

class MyApp < Window
  def initialize
    super 200, 200, false
    @image =, "heart.png", true)
    @x = 10 # @image pos x
    @y = 10 # @image pos y
  def needs_cursor?
  def update
    if button_down? MsLeft and (@x..@x+@image.width).include?(mouse_x) and (@y..@y+@image.height).include?(mouse_y)
      puts "clicked" if @image.get_pixel(mouse_x - @x, mouse_y - @y)[3] != 0.0
  def draw
    @image.draw(@x, @y, 1)

Just replace heart.png with your image of choice! Ask if anything isn't clear in this code.
Parent - By hans_soleil Date 2014-01-30 16:58
Thank you very much for your help! This really helped me a lot. Again, thank you. I really appreciate your help.
Parent - By jlnr (dev) Date 2014-01-30 20:21
You can also use Image#to_blob, which returns a binary string (and cache it), and then index into that -> image_blob[width * y + h]. That will then return an argb string. Not pretty, but 0ldsk00l.
Up Topic Gosu / Gosu Exchange / Clickable image?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill