• Steam recently changed the default privacy settings for all users. This may impact tracking. Ensure your profile has the correct settings by following the guide on our forums.

Lua question

ok so ive made small games with Lua, and have an ok handle with the basics, but i want to make a platform game, so i was looking around on the net for a good tut on how to use a tile map system. Needless to say i could not find one that really explained the code all that well, so if anyone knew of one or could find something im missing (because i know theres got to be one out there). Oh and one with scrolling would be nice as well, but not neccesary. Anyway any help is appreciated
 

A_Nub

Developer
Make your own ;) It is very good practice.

Here are some keywords to learn and will help u in making it fast and robust (hopefully)

Two Dimensional array (or table)[i prefer to store my maps in a 1D array an use a simple % to calculate the index]

Iteration (to go through the tile map array)

Offset (used for scrolling and culling)

Culling (used to not render unseen tiles)

Sprite (render part of an image)

Sprite Sheet (so u only have one image in mem)

Multiplication (to render each tile in its proper grid location)

Layers (multiple tile maps to create higher detail)



And that should get you on your marry way, then when u got that working come back and I'll give u another set of words for Tile Map Collisions!
 

Hardrive

Contributor
Is there a reason why you don't use two dimensional arrays? Wouldn't it be less efficient as well as much more difficult to read?
 

Freshmilk

is Over 9000
Is there a reason why you don't use two dimensional arrays? Wouldn't it be less efficient as well as much more difficult to read?

I don't always do everything as optimized as possible either. Even though I'd use a two dimensional array for the tile map, when I need something to store the co-ordinates of the player, I'd use two seperate variables rather than one array. I don't really know why, it just makes more sense to me that way.
 
ok so thanks for the help so far i can know for my purposes blit the tiles on the screen and make it look how i want (it was alot easier than i thought as is most things cause i overthink everything). Anyway i have attempted to make it scrolling, but all i could do was use a simple math formula and an if, elseif statement, but thats just a bandaid because i have no clue how i would do it more than once as my method wouldnt work lol. so any help is again appreciated
 

A_Nub

Developer
That word would be Offset.

Basically you need to keep a table of information about the map, ie the location the map is rendered the sprite sheet and the map itself. So basically its addition :D you add the maps X,Y to the tiles X,Y et voila!

Then for culling you can calculate the closest tile using division!

psuedo
start tile x = abs(mapX)/tileWidth

Then for scrolling all you do is treat the map like a sprite :D and move its X,Y
 

Emmy The Joker

New Member
I don't always do everything as optimized as possible either. Even though I'd use a two dimensional array for the tile map, when I need something to store the co-ordinates of the player, I'd use two seperate variables rather than one array. I don't really know why, it just makes more sense to me that way.
My freshmilk has his own special way of doing things. :p

I use(d) arrays. :cool:

I can answer the scrolling part. It's dead simple. :p

Think of the screen as graph.

The horizontal is X, vertical is Y. Just like in math class. :)

What is X = 1 in a graph? A line going straight up and down, and it's 1 unit right of the center. You start adding for it to move right or subtracting to X for it to move left. Simple. :)

I'd show you code but I've only coded on PSP and don't know if you are too and I have not looked at Lua code for over a year. :blushing:
 
thanks its always good to get more help lol. but right now its slow going trial and error and such, but this thread has really helped. and yes im coding for the psp. anyway all the help is greatly appreciated
 
Top