Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Loading Tiles
- - By funkymonkey Date 2015-06-02 14:31
Ok so I got my png sheet with 20x40 pixel tiles for whatever tileset I want to build.

Great so now I turn this into an array of like 76 images.  awesome

ok we're in the TilSet class..  we are writing our own draw method.  but wait a sec.  how am i going to draw the proper coordinates?  I know I'm missing a few things here..  one of which is using the window object in the initialize possibly and using those attributes for width and height to divide by the dimensions of the tile.  Besides that I don't know what steps to take.

A lot of tutorials online show you how to use a gem to do it or a JSON file.  but I'd like to learn the native way of doing it with Gosu first before getting fancy with yaml or something similar to handle large data collections.

also the @grid data collection is containing 0's because this is the walkable area.  it's going to contain 0's and 1's for walkable and non-walkable area.  Right now I'm trying to get a map to render correctly for one large walkable area.

Any advice is appreciated!

p.s. I know the x,y coordinates that are being drawn are just indices.  I'm wondering if they should be pointing to a value perhaps?  and that would be the x,y coord of each cell?   I'm self taught but have been learning ruby for almost a year and opening computers since my ibm ps/2 at age 12..

https://gist.github.com/genericlady/d89056eed4dca91f9516
Parent - By jlnr (dev) Date 2015-06-02 17:55
1. You don't need to pass a window reference around anymore in Gosu 0.9 :)
2. In Gosu 0.9, you can also omit the third argument, "false", to the Window's super constructor.
3. I think you should be fine if you replace this line:
        @tile.draw(x, y, 0)
with:
        @tile.draw(x * TILE_WIDTH, y * TILE_HEIGHT, 0)
x and y are indices into the arrays here, and by multiplying them with your constants you can convert them to pixels.
Up Topic Gosu / Gosu Exchange / Loading Tiles

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill