Page 1 of 1

How to draw levels with images!

Posted: Sat Jul 21, 2012 6:20 am
by Banoticus
Have you ever been sick of writing - 1, 4, 1, 0, 0, 0, 0, 6, - to draw your levels. Because i am!
There has to be a simpler way.
How about using an image's colours for different blocks. A block-A pixel.
Can you please tell me how this is done so i can add it to my game Platformer X.

Re: How to draw levels with images!

Posted: Sat Jul 21, 2012 6:33 am
by Santos
Another Kind of World does this.

Check out world.lua and the levels directory. Here's an excerpt from world.lua:

Code: Select all

for x = 0, self.width-1 do
	for y = 0, self.height-1 do
		red, green, blue, alpha = self.baseImg:getPixel(x, y)
		if red == 255 and green == 0 and blue == 0 then
			love.graphics.draw(self.gfxNormal, x*8*self.scale, y*8*self.scale, 0, 3, 3)
		elseif red == 0 and green == 255 and blue == 0 then
			love.graphics.draw(self.gfxTop, x*8*self.scale, y*8*self.scale, 0, 3, 3)
		elseif red == 255 and green == 255 and blue == 0 then
			love.graphics.draw(self.gfxUnder, x*8*self.scale, y*8*self.scale, 0, 3, 3)
		elseif red == 0 and green == 255 and blue == 255 then
...

Re: How to draw levels with images!

Posted: Sat Jul 21, 2012 7:04 am
by T-Bone
There are tons of ways to solve this. I tend to create level editors in my games to get total control. Typically, I let the editor write automated lua code to files containing the data for each level.

Re: How to draw levels with images!

Posted: Fri Jul 27, 2012 2:03 am
by Nsmurf
well, i am currently using a system where i have a level .txt file that looks something like this:
111
101
111
(^that would be a box)

and it gets read into an array, where i use it in my game and in love.draw()
(love.draw renders the level)

if you want some code i can post some.

is this what you want?

Re: How to draw levels with images!

Posted: Tue Aug 07, 2012 9:15 pm
by awhite92
i like how "another kind of world" did it, so im working on my own version, ill create a new thread when its gotten anywhere.

Re: How to draw levels with images!

Posted: Wed Aug 08, 2012 1:34 am
by awhite92
this is what i made, let me know if it helps! although its pretty rough
Drawing Maps With Images

Re: How to draw levels with images!

Posted: Sat Aug 25, 2012 9:02 pm
by B-Man99
Stabyourself.net's OrthoRobot does this fantastically. Not sure how... its open source though, just like Mari0