December 6th, 2011 Battlemaps for Corona with SVG LevelBuilder – Let’s get started
- Battlemaps for Corona with SVG LevelBuilder – Let’s get started
Don’t reinvent the wheel! Use Karnak Games’ SVG Level Builder to make your levels!!
You’ll need to download/buy:
- KarnakGames’ Corona SVG Level Builder: here
- Borrow this map for testing purposes here from Wizards of the Coast here (Save it as ‘map1.jpg’ in a directory named ‘backgrounds’ your main directory where ‘main.lua’ lives. You can use ANY map you like, just follow the basic principles described below)
- Inkscape, here (OS X or Windows, perfect!)
- The SVG Level Builder iOS templates here (Follow the directions on that page for installation)
Now press Ctrl+Shift+L to bring up the layers window:
We want to add another layer and name it ‘background’, so click on the blue “+” and name the new layer accordingly:
Make sure that the background layer is highlighted, then go to File->Import and we’ll choose the map we downloaded named “map1.jpg”. When it come into Inkscape, it may be off-center. Adjust the X and Y coordinates highlighted below to 0 and 0:
Whew! OK, we’re done with setup. Click the little lock icon next to the layer named ‘background’. This will prevent us from clicking on it accidentally. Then click on the layer named ‘Game’:
NOW we get to do the fun stuff like placing objects that will be physics object in our game. Think of it like a giant piece tracing paper where you draw lines and shapes around the objects you DONT want players to be able to walk ‘through’ and it will bounce other objects off of it.
Well, I made a small quick screencast of me tracing some outlines and drawing some rectangles here:
We just save it out as test1.svg.
Now we can paste the following into our ‘main.lua’ file. Create it if you haven’t already:
local svg = require("svgparser") local levelBodies = svg:new("test1", {drawMode = "hybrid"}) physics.setGravity( 0, 0 ) function AddBouncies() for i=1,10 do local tempX = 130 --math.random(0,display.contentWidth) local tempY = 110 --math.random(0,display.contentHeight) local tempRadius = 2 local circleMaterial = { density = 15.0, bounce = 0.5, radius = tempRadius, friction = 5.0 } local tempCircle = display.newCircle(tempX,tempY,tempRadius) tempCircle:setFillColor(255,150,0) tempCircle.alpha = .5 tempCircle.rotation = 0 physics.addBody( tempCircle, circleMaterial ) tempCircle.isFixedRotation = true local tempValue =3.5 tempCircle:applyLinearImpulse(math.random(-tempValue,tempValue),math.random(-tempValue,tempValue)) end end AddBouncies()
..and make sure that all the following files/directories are in your directory (Note: ‘backgrounds’ is a directory where our map1.jpg file resides, and of course the svgparser.lua and xmlparse.lua you got from KarnakGames)
So compile and run it and you should see:
Sorry if it’s a little small, you can always watch it fullscreen but what we’re really interested in is 2 things;
- That the level physics objects are being loaded from the Inkscape file we saved out
- My ‘AddBouncies’ function throws a bunch of balls around in the dungeon chamber and YES! They bounce around and off the walls we just created!
local svg = require("svgparser") local levelBodies = svg:new("test1", {drawMode = "hybrid"})
- I didn’t make the map, I swiped it from the WOTC site
- KarnakGames made a great level editor (That I haven’t even scratched the surface on, you can see his site’s demo here)
- You only need 2 lines of code to get the physics and graphics into your Corona SDK app






