Two questions...

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
User avatar
Gromlick
Prole
Posts: 16
Joined: Thu Oct 09, 2008 8:39 pm

Two questions...

Post 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?
User avatar
Gromlick
Prole
Posts: 16
Joined: Thu Oct 09, 2008 8:39 pm

Re: Two questions...

Post 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?
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: Two questions...

Post 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.
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Two questions...

Post by cag »

I think you can use setColor(255, 255, 255, alpha) to do alpha-blended textures.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Two questions...

Post 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 },
 }
User avatar
Gromlick
Prole
Posts: 16
Joined: Thu Oct 09, 2008 8:39 pm

Re: Two questions...

Post 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
Happy_G
Prole
Posts: 8
Joined: Wed Dec 31, 2008 6:33 am

Re: Two questions...

Post 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.
User avatar
Gromlick
Prole
Posts: 16
Joined: Thu Oct 09, 2008 8:39 pm

Re: Two questions...

Post 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. ^^
Happy_G
Prole
Posts: 8
Joined: Wed Dec 31, 2008 6:33 am

Re: Two questions...

Post 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 ^^
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], slime and 4 guests