Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / How to edit the rect
- - By Andrek Date 2012-02-29 17:10
Hello, I need to know how to edit the rect, something like this:

@image.rect_x = x
@image.rect_y = y
@image.rect_width = width
@image.rect_height = height


or

@image.set_rect(x, y, width, height)

Thank you very much.
Parent - - By Spooner Date 2012-03-01 01:06
You can't resize existing images directly, even with Texplay.

The way you can mimic this is to create a new image and splice a section of the old image onto it. Something like this (assuming you have a 64x64 image that you want to crop down to the centre 32x32 region):

@cropped_image = TexPlay.create_image $window, 32, 32
@cropped_image.splice @original_image, 16, 16
Parent - - By Andrek Date 2012-03-01 12:09
Is what I need but I have a problem:

When I use:

@original_image.insert(image, x, y)

And then use:

@cropped_image.splice(@original_image, x, y)

"splice" ignores the images inserted with the method "insert".

Is there any way to not ignore?. Thank you very much.
Parent - - By Spooner Date 2012-03-01 14:37
I am not sure what you mean by ignore, but I suspect you need:

@cropped_image.splice(@original_image, x, y, :alpha_blend => true)
Parent - By Andrek Date 2012-03-01 17:53
Let me give an example of the error code (need an image):

require 'gosu'
require 'texplay'

class Window < Gosu::Window
  def initialize
    super(640, 480, false)
    # Try this code
    @original_image = TexPlay.create_image(self, 32, 32)
    @original_image.rect(0, 0, 5, 5, :color => :red) # later: Comment this line.
    @original_image.insert(Gosu::Image.new(self, 'image.png'), 6, 0)
   
    @cropped_image = TexPlay.create_image(self, 100, 100)
    @cropped_image.splice(@original_image, 0, 0)
  end
 
  def draw
    @cropped_image.draw(0, 0, 0)
  end
end

Window.new.show


I need to use Gosu::Image.new(self, 'image.png') and not 'image.png'.

Look how clear the image(@original_image.insert) when using a rect. Thank you very much.
Up Topic Gosu / Gosu Exchange / How to edit the rect

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill