Learning About Game Loops/Etc

Greetings,

I’m a junior SQL developer (about 2 years experience in a professional capacity) wanting, in my free time, to learn a bit about application development. I thought LUA/Corona would be a good place to start the learning process. I know a good bit of HTML, CSS, and Javascript, and have some experience with C#, but that’s about the length of my programming knowledge.

I’ve been working through some tutorials and have a fair (for a newbie, anyways) understanding of event listeners, buttons, etc. I’d like to expand my knowledge to the point where I could develop a straightforward turn-based RPG-- something with the bare minimum, just to teach me how Corona deals with game loops. Basically, just allow the PC and and NPC to “Attack”-- no skills/strategy/etc-- but be able to go through an entire battle sequence. It’d require the PC to actually press the “Attack” button, but the NPC would attack automatically.

Think this is a fine approach to take? Any tutorials you all could recommend on how to set something like this up? There are plenty of tutorials on physics-based games, but at this point, I’m more interested in actually learning about the game loop and “scenes” (I think they’re called) than I am creating something with physics.

Much obliged! [import]uid: 191085 topic_id: 32532 reply_id: 332532[/import]

If you just want to do a D&D style system where the player presses attack, then an event listener on the attack button can start a chain of actions (roll initiative, winner attacks, looser attacks, display results) without a game loop at all.

But if you want to move the NPC’s have them initiate attacks and such, then a game loop is more appropriate.

However Corona being an event driven system doesn’t have a clear game loop that you might write in C. But what it does have is an special type of event called “enterFrame”. This event fires 30 times per second or 60 times per second depending on your frame rate. So basically every time it’s ready to update the screen, the event fires and you can do stuff. I typically do something like this:

local function gameLoop(event)  
-- my looping actions go here  
end  
  
Runtime:addEventListener("enterFrame", gameLoop)  

You can move your NPCs and do other things all inside that gameLoop. [import]uid: 19626 topic_id: 32532 reply_id: 129333[/import]

Good points; thanks, Rob. Knowing about enterFrame gave me context to move forward with research, such as:

http://www.coronalabs.com/blog/2012/02/21/understanding-coronas-enterframe-event/

Appreciate the help. Looking forward to playing with it tonight.

[import]uid: 191085 topic_id: 32532 reply_id: 129357[/import]

If you just want to do a D&D style system where the player presses attack, then an event listener on the attack button can start a chain of actions (roll initiative, winner attacks, looser attacks, display results) without a game loop at all.

But if you want to move the NPC’s have them initiate attacks and such, then a game loop is more appropriate.

However Corona being an event driven system doesn’t have a clear game loop that you might write in C. But what it does have is an special type of event called “enterFrame”. This event fires 30 times per second or 60 times per second depending on your frame rate. So basically every time it’s ready to update the screen, the event fires and you can do stuff. I typically do something like this:

local function gameLoop(event)  
-- my looping actions go here  
end  
  
Runtime:addEventListener("enterFrame", gameLoop)  

You can move your NPCs and do other things all inside that gameLoop. [import]uid: 19626 topic_id: 32532 reply_id: 129333[/import]

Good points; thanks, Rob. Knowing about enterFrame gave me context to move forward with research, such as:

http://www.coronalabs.com/blog/2012/02/21/understanding-coronas-enterframe-event/

Appreciate the help. Looking forward to playing with it tonight.

[import]uid: 191085 topic_id: 32532 reply_id: 129357[/import]

Oh and OMG since you’re already SQL savvy don’t forget to check out the open source D&D database. I posted a small link here:

http://developer.coronalabs.com/forum/2011/12/15/sqlite-and-dd-database-learning-fun

Rock it and post progress!!! :slight_smile:

-Mario

[import]uid: 11636 topic_id: 32532 reply_id: 129429[/import]

Oh and OMG since you’re already SQL savvy don’t forget to check out the open source D&D database. I posted a small link here:

http://developer.coronalabs.com/forum/2011/12/15/sqlite-and-dd-database-learning-fun

Rock it and post progress!!! :slight_smile:

-Mario

[import]uid: 11636 topic_id: 32532 reply_id: 129429[/import]

Interesting… I hadn’t considered tying my SQL skills into this stuff. Do many people use (or would they use, if they were proficient) SQL tables instead of XML/etc for managing data? If so, that would be pretty awesome!

The wife and I passed out candy for Halloween until late, so didn’t have a chance to continue working last night, but looking forward to taking a look at it again ASAP. [import]uid: 191085 topic_id: 32532 reply_id: 129492[/import]

Interesting… I hadn’t considered tying my SQL skills into this stuff. Do many people use (or would they use, if they were proficient) SQL tables instead of XML/etc for managing data? If so, that would be pretty awesome!

The wife and I passed out candy for Halloween until late, so didn’t have a chance to continue working last night, but looking forward to taking a look at it again ASAP. [import]uid: 191085 topic_id: 32532 reply_id: 129492[/import]