Can we create a Level Editor via Corona GE?

I came from Torque Game Builder (2D game engine)

And i am planing to create a platform based game. Do you think it’s feasible (possible) to create a Level Editor via Corona GE
then via the Level Editor, we create our games? Coz if it’s possible to create a level editor, it would save a lots of time adjusting the layout [import]uid: 10373 topic_id: 3534 reply_id: 303534[/import]

It’s perfectly possibly to create a level editor for a game that uses something like a tile system (like a Platformer), whether you’d want (or be able) to create that engine directly in Corona is really up to you. Creating a standard desktop application that can export a level out into either XML or JSON that your game can then read would work fine. [import]uid: 5833 topic_id: 3534 reply_id: 10663[/import]

hi GrahamRanson

do you have any references? Or is a Level Editor a roadmap for Corona GE? [import]uid: 10373 topic_id: 3534 reply_id: 10664[/import]

I doubt that there will be a level editor on the roadmap as it would be hard to make one that covers all the different game types users would want without taking away dev time for Corona itself.

You have two options really, you could either create an editor yourself or simply use one of the existing tile map editors such as this or this and then just deal with the XML output in your game.

I was actually thinking of writing something like this myself. [import]uid: 5833 topic_id: 3534 reply_id: 10691[/import]

yes please! :wink:

i’ll check if those apps work with CrossOver (run windows apps on mac) [import]uid: 6645 topic_id: 3534 reply_id: 10773[/import]

I’m currently just trying to finish off my first game, Tuucha, but once that is done (or I want a short break) I will have a look at getting some kind of importer made. [import]uid: 5833 topic_id: 3534 reply_id: 10776[/import]

some of this code might help :slight_smile:
http://www.qj.net/psp/homebrew-applications/lumm-lua-map-maker-2d-tile-map-editor.html
http://love2d.org/wiki/Tutorial:Tile-based_Scrolling [import]uid: 6645 topic_id: 3534 reply_id: 10779[/import]

Graham,

there’s a TMX tilemap parser in the .love file here
http://love2d.org/forums/viewtopic.php?f=5&t=2103&p=21925&hilit=cannon#p21925

note: .love files are zip files containing the lua code and assets :slight_smile:

this code should also be quite “easily” translatable using GE SpriteSheets

http://love2d.org/wiki/Tutorial:Efficient_Tile-based_Scrolling

j [import]uid: 6645 topic_id: 3534 reply_id: 10781[/import]

Thanks for the links, will start looking into things now. [import]uid: 5833 topic_id: 3534 reply_id: 10782[/import]

actually that efficient scrolling code is really no different than this:
http://pixels.ph4.se/2010/10/tilemaps-with-corona-part2/

but the map parser in the other link may be useful [import]uid: 6645 topic_id: 3534 reply_id: 10784[/import]

I have a very basic version working, currently it can parse a map created by Tiled that contains just 1 tileset but multiple layers (however more than 1 layer is likely to go screwy for now). Spacing doesn’t work currently (as I’m not sure how that would work with Coronas spritesheets) so only use tileset images that don’t have borders around the tiles.

I also haven’t implemented properties, which I think will be the next thing I add.

If anyone is interested I can upload the early (only a few hours work on it) preview build with a sample map (very small) just so you can have a look at it.

Edit - It now supports properties. [import]uid: 5833 topic_id: 3534 reply_id: 10817[/import]

did you look at the parsemap function in main.lua in the cannon.love package? that shows how to parse the multiple tileset layers from a .tmx file

below is a print_r of the parsed map data
http://pastebin.com/zW6ss8fD

the only thing i removed was the bit he uses to create a spritesheet

[lua]–map.tileset[i].image = tile.new()
–map.tileset[i].image.load(map.tileset[i].filename,map.tileset[i].height,map.tileset[i].width)
–map.tileset[i].image.newBatch(20*25)[/lua]

I’m not really working on this tilemapper at the moment, but i am happy to test and help where i can

regards
j

[lua]table: 0x232886a0 {
[tileheight] => “32”
[tilewidth] => “32”
[tileset] => table: 0x232886a0 {
[1] => table: 0x2323dce0 {
[name] => “ground”
[label] => “tileset”
[height] => “32”
[filename] => “ground1.jpg”
[firstgid] => “1”
[width] => “32”
}
[2] => table: 0x2323dce0 {
[name] => “adds1”
[label] => “tileset”
[height] => “32”
[filename] => “adds1.png”
[firstgid] => “2049”
[width] => “32”
}
[3] => table: 0x2323dce0 {
[name] => “other1”
[label] => “tileset”
[height] => “32”
[filename] => “other.png”
[firstgid] => “2561”
[width] => “32”
}
[4] => table: 0x2323dce0 {
[name] => “ground”
[label] => “layer”
[height] => “192”
[data] => table: 0x2612f3d0 {
[1] => table: 0x2612f270 {
[1] => “1”
[2] => “2”
[3] => “3”

etc[/lua]
[import]uid: 6645 topic_id: 3534 reply_id: 10821[/import]

I had a quick look at the cannon stuff, then did it my own way :slight_smile:

The multi tileset stuff should be pretty straight forward, I’m just pretty tired so will have a look at it tomorrow.

I have uploaded version 0.1 to my site here.

If you get a chance to play with it (there isn’t much there yet, it literally just loads it up right now) then please pass on any feedback you think of. There aren’t really any comments in the code yet and only very basic instructions on my site. I will sort both those out when the code is a bit more stable.

The Tiled editor has a build for OS X as well as Windows so if this all works out it could turn out to be useful. [import]uid: 5833 topic_id: 3534 reply_id: 10822[/import]

this isn’t perfect but shows 8 way tile scrolling. click the edges of the screen to scroll in that direction.

there is an extra row and an extra column outside the screen to allow for scrolling 32 pixels before redrawing the tiles

ie this is moving 11x16 tiles around that are 32x32px in size. it’s using the equivalent of Flash gotoAndStop method.
get tileset.png from here:
http://love2d.org/w/images/b/b5/Resource-ExampleEfficientTileset.png

[lua]require(“sprite”)

local map – stores tiledata
local mapWidth, mapHeight – width and height in tiles

local mapX, mapY – view x,y in tiles. can be a fractional value like 3.25.
local oldMapX, oldMapY

local tilesDisplayWidth, tilesDisplayHeight – number of tiles to show

local tilesetImage
local tileSize = 32 – size of tiles in pixels
local tilesetSprite

local moveX = 0
local moveY = 0
local moveAmount=1/32 – in tile units, so to move 1px at a time set moveAmount to 1/tileSize
function load()

setupMap()
setupMapView()
setupTileset()

end

function setupMap()
mapWidth = 60
mapHeight = 40

local i=1

map = {}
for x=1,mapWidth do
map[x] = {}
for y=1,mapHeight do
– pick a random tile for now
map[x][y] = math.random(1,70)
i=i+1
end
end
end

function setupMapView()
mapX = 1
mapY = 1

tilesDisplayWidth = 11 --(10 * 32 = 320, plus 1 spare column)
tilesDisplayHeight = 16 --(15 * 32 = 480, plus 1 spare row)
end

function setupTileset()

spritemap = display.newGroup()

spriteSheet = sprite.newSpriteSheet(“tileset.png”, tileSize, tileSize)

spriteSet1 = sprite.newSpriteSet(spriteSheet, 1,100)

for x=1,tilesDisplayWidth,1 do
for y=1,tilesDisplayHeight,1 do
local tilesprite = sprite.newSprite( spriteSet1 )
tilesprite.x = (x-1)*tileSize+(tileSize/2)
tilesprite.y = (y-1)*tileSize+(tileSize/2)
spritemap:insert(tilesprite)
end
end

updateTilesetBatch()

end

function updateTilesetBatch()

local i = 1
for x=1, tilesDisplayWidth,1 do

for y=1, tilesDisplayHeight, 1 do
spritemap[i].currentFrame = map[x+math.floor(mapX)][y+math.floor(mapY)]
i = i + 1
end

end

end

– central function for moving the map
function moveMap(dx, dy)

oldMapX = mapX
oldMapY = mapY

mapX = math.max(math.min(mapX + dx, mapWidth - tilesDisplayWidth), 1)
mapY = math.max(math.min(mapY + dy, mapHeight - tilesDisplayHeight), 1)

spritemap.x = 0-((mapX * tileSize)%tileSize)
spritemap.y = 0-((mapY * tileSize)%tileSize)

if math.floor(mapX) ~= math.floor(oldMapX) or math.floor(mapY) ~= math.floor(oldMapY) then
updateTilesetBatch()
end
end
function update(event)

– if move amount is set, move the map
if(moveX~=0 or moveY~=0) then
moveMap(moveX,moveY)
end

end

function onTap(event)

– tap edges of screen to move

if(event.x < 100) then
moveX=-moveAmount
elseif(event.x > 220) then
moveX=moveAmount
else
moveX=0
end

if(event.y < 100) then moveY=-moveAmount
elseif(event.y > 380) then moveY=moveAmount
else moveY=0
end

end

load()

Runtime:addEventListener(“enterFrame”,update)
Runtime:addEventListener(“tap”, onTap)[/lua] [import]uid: 6645 topic_id: 3534 reply_id: 10825[/import]

good stuff!

maybe other people could comment on what functions might be required? I don’t think loadMap should return the layout as such.

something like
loadMap(…) – load the data

prepareMap({rows=n,cols=n}) – allows to draw only part of the map (ready for scrolling… adds 1 row right and bottom). if nothing passed just draw it all as one big displaygroup,

drawMap() - draw the map, dependent on prepareMap

I don’t know if you plan to implement scrolling but that could be a separate module that ties in to how the map is prepared.

  1. scroll the map as 1 big displaygroup… probably good for games that are 3 screens high or wide etc
  2. scroll the map using currentFrame changes on a set number of sprites (from prepareMap called with columns)

let’s not even mention parallax yet :wink:

j [import]uid: 6645 topic_id: 3534 reply_id: 10827[/import]

Yea I think the scrolling should be separate, that way for games that don’t need it it can just be ignored. Lime is simply the loader code, I will create something else for scrolling.

Yea I think separating out the loading, preparing and drawing would be a good thing.

Haha, parallax. Eventually :slight_smile:

Yea if anyone else has any feedback etc please say so. All help is appreciated. [import]uid: 5833 topic_id: 3534 reply_id: 10829[/import]

i tried some other maps but they wouldn’t load … i guess that’s because they were “orthagonal” type etc. not sure. i’ll see if i can find some example .tmx files that might be of use to you though

http://paulsonapps.wordpress.com/2010/03/12/tutorial-1-tilemap-with-collision-game-cocos2d/
http://silveiraneto.net/2009/12/19/tiled-tmx-map-loader-for-pygame/ (spacing on this one)

[import]uid: 6645 topic_id: 3534 reply_id: 10831[/import]

Orthogonal ones should work, it’s isometric that I’m not sure about.

I’ve just uploaded a slightly modified version (0.2) that splits the creation (loadMap()) and preparing (map:prepare()) out, it also just shows that a map can be wider than the screen by simply scrolling right to left and back.

Could you send me the stuff for the tilemap that didn’t work? It probably uses something I haven’t implemented yet like multiple tilesets so would like to take a look at it if possible. [import]uid: 5833 topic_id: 3534 reply_id: 10832[/import]

just the one’s linked. for the cocos2d one it’s because he has margin and spacing
[import]uid: 6645 topic_id: 3534 reply_id: 10833[/import]

Ah right ok, will look at that tomorrow then. It’s 4am now and I really should be going to bed, the only problem is that Corona is just too much fun to play with, perhaps I should submit that as a bug :slight_smile: [import]uid: 5833 topic_id: 3534 reply_id: 10835[/import]