Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Stamp an object?
- - By Isen Date 2012-04-15 01:43
I'm new to Gosu.  I'm trying to write a tile-based engine, and what's probably a fairly obvious problem has arisen for me.  I can't write a separate variable for each of my 192 tiles!  Is there a way to simply stamp an image onto the screen?
Parent - - By jlnr (dev) Date 2012-04-15 03:35
What do you mean by stamping? :?
Parent - - By Isen Date 2012-04-15 13:31
I mean, can I take an image, place it somewhere (say, 0, 0), and then make a copy of it there, so that I can move my object away with a duplicate of it still at 0, 0.
Parent - By jlnr (dev) Date 2012-04-16 02:12
You may want to look at the CptnRuby.rb example. It has a tile map, and you could stamp tiles by just putting them in the tile array at the right place. Level editors usually work this way.
Parent - - By lol_o2 Date 2012-04-15 07:59
Well, to make "variables" for tiles, you could simply put them into array.
But for stamping, as you called, you can use:

@tiles=Window.record(map_width, map_height) do
## draw tiles here
end


And then draw @tiles as image.
Parent - - By Isen Date 2012-04-15 15:25 Edited 2012-04-16 00:01
I am using an array for the tiles.  My problem is finding a way to get all of my 100+ tiles that will be shown on the screen without having to assign each tile image its own variable.

Edit: Well actually, I suppose that I can just use ranges.  Yeah, that should work.
Parent - By Dahrkael Date 2012-04-16 15:21
you can draw an image multiples times, just call image.draw with different position
Parent - - By RavensKrag Date 2012-04-20 07:44
EDIT: Wait, perhaps I just confused myself... it's rather late over here.  I'll just keep this post here just in case it's useful to someone :P

I believe what you're asking is the ability to access 100 unique types of tiles without having separate variables for each.

In that case you have two options:
1) Assuming the tiles are all the same size, put them into a spritesheet.  Load the sheet using Gosu::Image#load_tiles(), and then reference the tiles by indexing into the returned array.

2) If they are not the same size, or you prefer to reference them by name, you can resort to a more complex solution.  Store your tiles in a hash, where the keys are the names of the tiles, and the values are Gosu::Image instances.  I think this is probably overkill, but if that's what you want, then go right ahead.
Parent - By Jwosty Date 2012-04-20 12:56
Thanks for the reply, but it's been solved on another forum. This was (mostly) my post:

---

Images can be drawn multiple times to the screen; any number of times or not at all. Take this for example:

# Lets say that my_image is a 100x100 size image, and we want to stamp it 10x10 times
for x in 1..10
  for y in 1..10
    w, h = my_image.width, my_image.height
    # Multiply the sizes so the "stamps" don't overlap
    my_image.draw(x * w, y * h, 0)
  end
end


EDIT: Oh also, all the copies will stay until the screen is wiped (after each draw call)

---

The last line was his main issue.
Parent - By Jwosty Date 2012-04-17 03:21
Check on Coders' shed; I answered it there. ;)
Up Topic Gosu / Gosu Exchange / Stamp an object?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill