Page 1 of 1

Two questions...

Posted: Wed Oct 22, 2008 8:14 pm
by Gromlick
One:
Is there any way to display a sprite in love with a transparent background? The objects I want to display onscreen have an unfortunately non-rectangular sort of shape to them. :(

Two:
I know there's a way to do this, but I don't know how in Lua: how can I make a variable size two dimensional array? I'm making a tile based map that I've been using just numbers to describe up until now, so it wasn't a real problem to code a map like this:

Code: Select all

	map={

	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
	}
What I want to do is code maps by tile objects rather than numbers, as I would like individual tiles to have variable states... But coding that like above would be very painstaking, so I was trying to populate an empty two dimensional array through a pair of nested for/do loops (which of course doesn't work). Is there an easy way to do this? Or do I need to come up with a different solution?

Re: Two questions...

Posted: Wed Oct 22, 2008 8:41 pm
by Gromlick
Alright, after some long, painful hunting I found my answer to number two on an old Lua tutorial I found. :)

But yeah, so does love have alpha settings? Masks?

Re: Two questions...

Posted: Wed Oct 22, 2008 10:44 pm
by surtic
If you use PNG files for bitmaps, they support transparency (and semi-transparency) and LÖVE presents them correctly.

Many of the examples, tutorials and demos contain such bitmaps, have a look in http://love2d.org/docs/ExampleList.html, you can use the example browser to see the examples.

Re: Two questions...

Posted: Thu Oct 23, 2008 2:48 am
by cag
I think you can use setColor(255, 255, 255, alpha) to do alpha-blended textures.

Re: Two questions...

Posted: Thu Oct 23, 2008 6:09 pm
by rude
If you want to set the alpha of the entire image, then yes, you can use setColor in love.color_modulate mode.

EDIT:
About 2D arrays: your approach should be fine. When you want to resize the map, you just add new elements at the end at the end of each row, and add extra rows at the end of the map-table:

Code: Select all

 -- Resize from 4x4 to 5x5
 -- n = new
 map={
    { 1, 1, 1, 1, n },
    { 1, 0, 0, 0, n },
    { 1, 0, 0, 0, n },
    { 1, 0, 0, 0, n },
    { n, n, n, n, n },
 }

Re: Two questions...

Posted: Fri Oct 24, 2008 4:02 pm
by Gromlick
Thanks! I'm going to have to sit down and play with this some more when I get some time to myself... *if* I get time to myself. :P

Re: Two questions...

Posted: Wed Dec 31, 2008 6:48 am
by Happy_G
Gromlick wrote:Alright, after some long, painful hunting I found my answer to number two on an old Lua tutorial I found. :)

could you point me in the direction of this please? i want to create some random generating maps which seems easiest to me to do as an array. and im not only new to LOVE and lua scripting but im new to programming as well so im trying to make my first actual 2d game out of this.

Re: Two questions...

Posted: Fri Jan 02, 2009 10:39 pm
by Gromlick
I feel terrible saying this, but I can't find it again... ^^;

I can however, tell you what i did:

I started with a 'map' array defined like above, and just started assigning 'tile' objects as appropriate. My 'tile' objects are listed in their own array, so I can have numbers representing specific types of tiles,
i.e. 1=stone floor, 2=wooden wall, etc.
'tile_map' is what I called the final array populated with 'tile' objects.

Code: Select all

for y=1, map_h do -- map_h is the map's height
	tile_map[y] = {} -- makes a new row
for x=1, map_w do -- map_w I hope is obvious ^^
	tile_map[y][x] = Tile:new {} --populates the 'tile_map'
	tile_map[y][x]:set_tile( tile[ map[y][x] ] ) -- assigns the new tile to it's corresponding number on 'map'
end
end
If it helps any, I'm really not much of a programmer either, though I've had a few classes. Always happy to help if I can. ^^

Re: Two questions...

Posted: Sat Jan 03, 2009 12:52 am
by Happy_G
thats quite similar to what i finnally figured out, thank you for responding.

my problem was not understanding how Lua handled arrays i didnt realize i didnt have to define the size of the array so once i knew that and how to define an array i was fine. i now have a working game and am playing it and figureing out what i want to change.

and if anyone comes here with the same question i had creating an array is easy ^^

array = {}

then fill it in as you wish ^^