I Require Aid.

Posted by Charlie Carlo on Aug. 9, 2012, 10:39 p.m.

Okay, so as you may know, I created a super awesome lighting engine.

As you may not know, I have no idea how to handle tiles with code.

My current way to put a background and foreground into the room is create them both with tiles separately and save them as a huge image and put it in the game. As you can imagine, this is retarded.

The reason for this is, the view isn't actually a view. Instead of the view looking at different parts of an image, the image just draws itself at different parts depending on where the view is. Poly taught me that crazy technique, but I don't think he uses tiles.

I don't know if I can use tiles with this system, though, which sucks.

I want to just place tiles by hand in the room editor. But in order to do this I'll have to alter my drawing script to:

1. Hide all tiles (because otherwise they'll draw weirdly on top of the surface.)

2. Draw all tiles at depth 1 onto a surface, with an offset of -view_xview, -view_yview.

*My current script goes here

3. Draw all tiles at depth -1 onto the surface with the same offset.

Basically, I'm asking if anyone knows how to draw all tiles at a certain depth onto a surface like a background.

Plox, guys, I really need help here.

Comments

ludamad 12 years, 3 months ago

For loops are not elitism. Either way, I wasn't being elitist in the slightest. If anything, I have to hand it to GM for allowing people to make games without first understanding these concepts.

I said nothing about not using GM, too. My most recent blog post, though a bit hard on GML, gave some tips for using GML in a way focused on creating abstractions, which is important in large projects.

Castypher 12 years, 3 months ago

Nah, sorry man. I've just seen a lot of people move on up the ladder and that's great for them. But when they sit there and bash the gateway tools and software, it feels a bit odd. That's great that you have a knowledge of programming, but there's no need to shove it in peoples' faces when most people really don't care as much as you do.

I wasn't talking about the for loops, really, mostly your (and many other peoples') constant attitude that GM sucks (not saying it doesn't, but I don't rant about every reason it's a terrible tool). It works great for what it does, and while it may not be the most optimized program, it's still capable of some impressive things. But you're not the only person I'm talking about on this subject.

I wouldn't have developed an interest in game design if I hadn't used GM. I owe it that much and I think fondly of it for that reason.

You're not really my target so much as all the incessant people I've seen complaining about GM. You just reminded me of it. Also, programmers in general are elitist. Just saying.

Charlie Carlo 12 years, 3 months ago

GM does what I want it to, usually, fairly well.

I don't really need a better tool, considering I just make shitty freeware as a hobby; GM is essentially perfect for my ends.

I'm not too too interested in coding, but I figure picking up knowledge of it won't hurt.

Juju 12 years, 3 months ago

Hokay, let's get this back on topic.

Charlie Carlo 12 years, 2 months ago

Okay total necro post but I'm back on this again. I have kind of a plan to use for loops at the beginning of room creation to find the tiles on each depth. The thing is, I'd need two for loops to get the x and y for one or more function. I'm not sure this is possible though. Is there any way to structure a for loop to give me two results at once?

var ux, uy;
tile_layer_hide(1);
surface_set_target(sur_bg);

//for loop how do

tile_add(tile_get_background(tile_layer_find(1,ux,uy)),
	tile_get_left(tile_layer_find(1,ux,uy)),
	tile_get_top(tile_layer_find(1,ux,uy)),
	tile_get_width(tile_layer_find(1,ux,uy)),
	tile_get_height(tile_layer_find(1,ux,uy)),
	ux,uy,1);

Something like this could work if "//for loop how do" was replaced with an/multiple actual for loop/s that could some how get me two variables at once, miraculously.

I mean, one for statement just keeps running until it's shut down right? How do I couple them together in such a way that they can work on getting me coordinates? Preferably checking by rows, left to right.

SPECTRE I NEED A HERO.

Pirate-rob 12 years, 2 months ago

I think this is what you are asking for?

for(ux = 0;ux < (number of tiles the room is across);ux+=1) {
for(uy = 0;uy < (number of tiles the room is down);uy+=1) {

tile_add(tile_get_background(tile_layer_find(1,ux,uy)),
tile_get_left(tile_layer_find(1,ux,uy)),
tile_get_top(tile_layer_find(1,ux,uy)),
tile_get_width(tile_layer_find(1,ux,uy)),
tile_get_height(tile_layer_find(1,ux,uy)),
ux,uy,1);

}}

Charlie Carlo 12 years, 2 months ago

You can do that? Put for statements in for statements? I didn't know if that'd like… blow something up or not.

I'll give it a try.

EDIT: It didn't work at all, but I blame the tile_add function. I did find a way to do this however, it involves making an object at a draw depth 1 more than the tiles and having it set the surface target. A clever idea I found while Googling the problem. So this problem has been solved, thank god.

Yaru 12 years, 2 months ago

For for loops, having one loop inside another loop is called NESTING them. It's vital to do anything complex (like cycling thru a 2-D grid of values). You can also have multiple with(){} loops in each other, as long as you keep track of what you're doing and who is OTHER from the perspective of the current loop. And of course you can mix for/with nesting.

As for Pirate-Rob's code, I'd do this instead of save some CPU:

for(c = 0;c < room_width/tilesize_x;c += 1){
for(d = 0;d < room_height/tilesize_y;c += 1)
t = tile_add(back,l,t,w,h,x,y)
//functions to get tile data into a 2-D array
}
}

Tile_add() BTW? I'd use tile_layer_find(), else you're creating more and more tiles all the time and will leak memory.

ludamad 12 years, 2 months ago

Quote:
You can do that? Put for statements in for statements? I didn't know if that'd like… blow something up or not.
= D.

Your first exposure to the fun world of nested loops. Just wait till you write them 5 for loops deep.

Of course, every for loop is already implicitly nested in GM because there's already a global for-loop iterating over all the objects (implemented in the GM runtime's language, of course)

sirxemic 12 years, 2 months ago

Quote:
You can do that? Put for statements in for statements? I didn't know if that'd like… blow something up or not.
With such a fresh mind on programming constructs I can only say - you haven't seen anything yet. ;)