How can I make a Map Editor?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

How can I make a Map Editor?

Post by louie999 »

I seem to be struggling on this one, I don't know how to make a Map Editor for my game D: anyone can give me some useful tips/help so I can make this?

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: How can I make a Map Editor?

Post by veethree »

You'll have to be more specific. How you implement a map editor can vary depending on the game. It would also help if we knew what exactly you're struggling with.
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

Re: How can I make a Map Editor?

Post by louie999 »

Well, my game is a tower defense game, the things I'm having problems with is:
1. Grid map
2. Loading a tile map
3. Saving the map

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: How can I make a Map Editor?

Post by IndieRetro »

louie999 wrote:Well, my game is a tower defense game, the things I'm having problems with is:
1. Grid map
2. Loading a tile map
3. Saving the map
Saving and loading can be very easy, I'd recommend using something like TSerial, basically what this does is converts a table into a string, which you can then save to a .lua file, and then you can directly require that file where you need it and access the data just like any other Lua table.
irc.freenode.org ##oodnet
http://exez.in/
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: How can I make a Map Editor?

Post by davisdude »

I'm gonna beat Robin to the punch and recommend Ser instead of TSerial ;)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

Re: How can I make a Map Editor?

Post by louie999 »

Ok I'll try TSerial and Ser and see which suits my needs better, though I have a new problem, how can I detect which "tile" the mouse is on, not the x/y but the tile, as the map editor I'm planning to make is gonna have a tilemap..

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
User avatar
DeltaF1
Citizen
Posts: 64
Joined: Mon Apr 27, 2015 4:12 pm
Location: The Bottom of the Stack
Contact:

Re: How can I make a Map Editor?

Post by DeltaF1 »

louie999 wrote:how can I detect which "tile" the mouse is on, not the x/y but the tile, as the map editor I'm planning to make is gonna have a tilemap..
To convert from screen x/y to map x/y coordinates, you need to divide the screen coordinates by your gridSize. For example, if your grid size is 64 pixels, then you could do this

Code: Select all

gridSize = 64

x = love.mouse.getX()
y = love.mouse.getY()

tileX = math.floor(x / gridSize) --"math.floor to round decimal answers down, so 2.11462 becomes 2 etc"
tileY = math.floor(y / gridSize)

tile = map[tileX][tileY] --"or map[tileY][tileX], depending on how your map is constructed"

doSomethingWithTheTile(tile)
(unrelated. Is there something wrong with comments in the code highlighter?
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Re: How can I make a Map Editor?

Post by bakpakin »

If your fine with not making a custom editor, I recommend using Tiled http://www.mapeditor.org/. It can be overly general, but it is a very good tool that exports to lua.

If you still want to make your own editor, I have a library, Editgrid https://github.com/bakpakin/Editgrid, that was made for level editors and the like. It helps for drawing fancy grids and is compatible with a couple of camera libraries.It also will autodetect the "tile" the mouse is on.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

Re: How can I make a Map Editor?

Post by louie999 »

DeltaF1 wrote:
louie999 wrote:how can I detect which "tile" the mouse is on, not the x/y but the tile, as the map editor I'm planning to make is gonna have a tilemap..
To convert from screen x/y to map x/y coordinates, you need to divide the screen coordinates by your gridSize. For example, if your grid size is 64 pixels, then you could do this

Code: Select all

gridSize = 64

x = love.mouse.getX()
y = love.mouse.getY()

tileX = math.floor(x / gridSize) --"math.floor to round decimal answers down, so 2.11462 becomes 2 etc"
tileY = math.floor(y / gridSize)

tile = map[tileX][tileY] --"or map[tileY][tileX], depending on how your map is constructed"

doSomethingWithTheTile(tile)
(unrelated. Is there something wrong with comments in the code highlighter?
Thanks dude
@bakpakin Ok, I'll give it a try. :)

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 58 guests