   Lua Love2D help!
  I'm just starting out learning Lua and using the Love2D framework, I have the basics of drawing images on the screen and moving them around and rotation, but I'm sort of stuck. I don't know if this is a limitation of Lua or just something I haven't learned but: How do I create multiple copies of enemies and spawn them in different locations? I've seen other Lua games do this, i'm just kind of stuck! Help!   
  First off it's not a limitation of Lua and to answer the second part of your question is.. well the basics of game programming. It's really hard to describe this without getting heavily into data structures but I'll try (eveything I know about the lua syntax I just read, so I'll be translating mostly from 'C').The easiest way to get started is to make an table(every other language would use an array) of enemies. You basicly want to itterate over this table in a loop to update information if they are alive what kind of enemy they are what kind of sprite to draw etc. I'd recommend making a large table to start(like 128ish entries for enemies) with dead enemies. The reason for this is it's typically expensive to add to the length of tables later.http://lua-users.org/wiki/TablesTutorial //read on tables before you get starteduse a 'control structure' (preferably a 'for' loop) to iterate over this table. within the loop you want want to call functions to do the following:Move an enemy (if alive):Draw an enemy (if alive):if the enemy is dead don't do anything in this loop. For spawning enemies you would take this table and set a variable within the table to alive and set their x&y chords.*Note that this isn't the best way but it's the simplest (I could think of) and enough to get you started. Once you become more skilled with data structures and functions you'll learn how to do this better.   ;  There's no need to keep a big table of dead enemies. For a simple game, just update all enemies in the table, and remove them when they're dead (meaning, set their key to nil so they get garbage-collected). IIRC, Lua tables are hash-maps. Most likely, each enemy will consist of a table itself, containing its position, etc.   ;  I'm still kinda confused, I'm trying to put the enemies into the tables. But all i have are separate variables for the image, x and y. Also, loops seem very fast, is there a way to do it using the gametime? Like spawn an enemy every 2 seconds or something?   ;Quote:Original post by theOcelotThere's no need to keep a big table of dead enemies.Like I said, I'm translating from 'c' arrays.The loop that iterates over the enemies should be fast, but your only supposed to call the loop once per game frame. To slow it down so your sprites don't run all over the place you have to implement timers(there's also delta timing but that can cause stability problems). This is found in love2d's API. http://web.ics.purdue.edu/~dcfritz/lovewiki/love11.htmlso in your games main loop you can use the gettime function to check how long it been since you've last checked the time. using the sleep function you can set your program to sleep for x amount of time. so if you wanted 60fps you want gettime + sleep to equal 1/60th of a second. If gettime is greater then 1/60th of a second, don't sleep.Edit: there's a better way to code it.. I didn't know love2d implemented callbacks. http://web.ics.purdue.edu/~dcfritz/lovewiki/love20.htmlin the second example where it says "if love.update then love.update(dt) end" you want to insert your enemy update code there.[Edited by - Tntricker on June 3, 2010 10:47:58 PM]