How to Rinse repeat…

Posted by Baltirow on Sept. 22, 2008, 4:47 p.m.

Building a level editor using the full capabilities of the existing Game Maker engine can lead to some interesting if not frustrating discoveries. The last of the bunch, was related to a certain facet of the option of built-in GM backgrounds’ ability to be set as a foreground. Picture the following: set a background to tile both horizontally and vertically, then set it as a foreground image. Result: the editor is obscured by a background :S. Since the setting is simply “set as foregroundâ€? there is no way of setting a depth for the rest of the editor that would allow it to be shown above the background.

Now there are several ways around this. An obvious one would be to emulate foreground behavior, by creating a fake background, for instance using draw_vertex_texture() in combination with texture_set_repeat(). This would become a bit troublesome if I only needed to repeat either vertically or horizontally.

But I have found another way, of which I was very amazed it existed. I bumped in it by accident. You see, if you tile, the chosen background is tiled indefinitely in the chosen tile direction. Or is it…? You see, when you tile horizontally, you can go as far to the left as to the right and you will see re-tiling wherever you go. If you would however tile vertically, this repetition stops when passing the origin… what? Yes if you get into negative space you are spared the sight of repeated tiles.

I'll explain it a bit better using the image below

For these two cases, the view of the room has the same origin as the editor around it. The background is set to repeat tiling both horizontally and vertically.

In Case 1, you see an editor window with a view on the room. If you set it to the foreground, you get the right picture and the editor and any objects below the foreground are obscured.

In Case 2, same editor, same room, but this time the view position has been shifted so that the origin of the room (point X=0, Y=0) lies within the room view (shown by the greyed-out area which is everything left and above the origin (or X<0, Y<0). If you set the background as a foreground now, only the part below Y=0 completely covers the screen. Everything above the origin is seen… because continuous tiling - for some unknown reason - does not go into negative Y space! (I apparantely forgot to remove the blocks in this one, imagine they aren't there :P)

So how does this help us? Well, if you make the view of the room and the editor independent, i.e. using two views, you can put the entire editor window in negative Y-space and simply use the built-in foreground setting with backgrounds and everything works fine.

Hope it is much more clear now ;), let's continue:

Thing is, now I will have to move the entire window into negative Y space. Though most of what I made was made using relative coordinates, it still will require a lot of rewriting. I’ll make sure to make everything easily movable now, before I run into more little GM gags.

In other news…

Next to tripping over this wire (I was almost finished with implementing backgrounds *shaking fist in anger*) I have been enjoying the little Cave Story medley link provided by the good patrons at IndieGames.

I have even downloaded the rip found in the comments (as the playing artist didn’t mind). The more busy pieces are a bit chaotic, but almost all the softer pieces are done very well, especially Gestation, Cemetary, Geothermal and Moonsong are done really well and come out stronger in this all-piano form. Some pieces are sadly missing, most notable being Meltdown 2 and Scorching Back. Also, Balcony was sadly cut short (perhaps he was tired playing so long already and eager to finish). I definitely recommend taking the time to listen through the entire 23+ minutes.

Comments

Chaz 16 years, 3 months ago

AWESOMEness:

Game + Level Editor = Game with lot's of intriguing levels.

Great way to go, instead of using gamemaker's built in level editor.

noshenim 16 years, 3 months ago

you can make layers invisible in the gm editor.

click on the dropdown list beside the magnifying glass on the editor.

s 16 years, 3 months ago

And why not emulate tiled texture drawing with a loop?

marbs 16 years, 3 months ago

I think it would be far easier to come up with a simple script to just draw the foreground image behind the editor GUI without using the built in foreground variable. This would also allow for more flexibility. You don't necessarily have to use the draw vertex stuff, just use a couple for loops and draw_background or something.

Also, level editors are a great idea :D

noshenim 16 years, 3 months ago

or you could leave it a background and use background_foreground[x] in the room creation code.

Baltirow 16 years, 3 months ago

@__Player__:

1. Yes you can turn off all backgrounds and all objects and all tiles, but you cannot do it per background or by a given tiling depth (not to mention object depth). So it is improving on GMs limitations.

2. I am using background_foreground. That's working fnie. The trouble is, that if you continuously-tile both horizontally as vertically, setting a background as foreground wil cover the screen.

@All:

If you read beyond the "use draw_vertex" part, you see it is also possible to do it otherwise. I guess I wasn't so clear on it the first time. I will add a picture and elaborate some more to clearify.