A function that constantly updates?

Hi all, me again. I, before using Corona, was developing my game using LOVE2D, as a graphics/game engine for pc. (LOVE2D was an engine for Lua). Now as I’m porting my game to Android, I’ve encountered a problem. In LOVE2D, in main.lua it was required that you have the bult-in function “love.draw()” What this function did was constantly update the program, such as variables and other functions. So for example, I could have this:

gamestate=“menu”

love.draw()

if gamestate==“menu” then

doMenu()

end

if gamestate==“play” then

startGame()

end

end

And this constantly updated and checked the gamestate… Now my problem is, i don’t know of any function that will do that on Corona, and my game, after you hit the play button, changes the gamestate to “play”. With LOVE2D, doing this would automatically call the startGame() function… But i don’t know of anything that does that… can someone help me out?

liimbix, 

Check out Composer, Corona’s scene management API. I think it’s what you’re looking for. The crew over at Corona-Geek has been doing video tutorials on it this month. You should check them out. Here’s the link to the API:

http://docs.coronalabs.com/api/library/composer/index.html

And here’s the link to the video tutorials:

http://coronageek.com/

Check out #124 and #125

I think this may be what I need! Let me play around with it and figure out what I’m doing, then I’ll mark your answer :slight_smile:

@James Sherburne I’m just wondering, (I looked at composer and got a bit confused) Do I require scenetemplate.lua in main.lua?

No, you don’t use the scene template with main.lua. With Composer, main.lua is simply the gateway to your scenes; very little happens in main.lua. You would require composer:

local composer = require( "composer" )

Then perhaps use a timer.performWithDelay function to load your first scene:

local function loadComposer (event) composer.gotoScene("menu) end timer.performWithDelay( 7500, loadComposer)

The scene template should be used for each of your scenes. Copy it and use it to start each of your scenes. It will take some time to learn, but is the go-to approach to designing games with Corona. Watch, Corona-Geek #124, Ed from Roaming Gamer does a tremendous job explaining Composer. 

Thank you James, I did a little bit of research, and your answer helped me a lot! I will have to do a total rewrite of my code, but that’s just how life is haha. Cheers! :-))

I think re-writing the code is probably your best bet – yes, it will take a lot more up-front work, but the resulting code will “fit” better into Corona and let you expand/modify it later much easier and faster.

Not knowing anything about Love2D, I assume love.draw() is a frame-by-frame rending funciton?  If so, a quick and dirty approach might be to catch the enterFrame event (look at addEventListener in the docs/example code) and call your “love.draw” routine there. 

Hey, jbp1, I did try the enterFrame event out, but all it did was freeze up my computer, because it played my audio like 1,000,000x over itself… But I figured out how to use Composer, and it’s working :slight_smile: Thanks!!

liimbix, 

Check out Composer, Corona’s scene management API. I think it’s what you’re looking for. The crew over at Corona-Geek has been doing video tutorials on it this month. You should check them out. Here’s the link to the API:

http://docs.coronalabs.com/api/library/composer/index.html

And here’s the link to the video tutorials:

http://coronageek.com/

Check out #124 and #125

I think this may be what I need! Let me play around with it and figure out what I’m doing, then I’ll mark your answer :slight_smile:

@James Sherburne I’m just wondering, (I looked at composer and got a bit confused) Do I require scenetemplate.lua in main.lua?

No, you don’t use the scene template with main.lua. With Composer, main.lua is simply the gateway to your scenes; very little happens in main.lua. You would require composer:

local composer = require( "composer" )

Then perhaps use a timer.performWithDelay function to load your first scene:

local function loadComposer (event) composer.gotoScene("menu) end timer.performWithDelay( 7500, loadComposer)

The scene template should be used for each of your scenes. Copy it and use it to start each of your scenes. It will take some time to learn, but is the go-to approach to designing games with Corona. Watch, Corona-Geek #124, Ed from Roaming Gamer does a tremendous job explaining Composer. 

Thank you James, I did a little bit of research, and your answer helped me a lot! I will have to do a total rewrite of my code, but that’s just how life is haha. Cheers! :-))

I think re-writing the code is probably your best bet – yes, it will take a lot more up-front work, but the resulting code will “fit” better into Corona and let you expand/modify it later much easier and faster.

Not knowing anything about Love2D, I assume love.draw() is a frame-by-frame rending funciton?  If so, a quick and dirty approach might be to catch the enterFrame event (look at addEventListener in the docs/example code) and call your “love.draw” routine there. 

Hey, jbp1, I did try the enterFrame event out, but all it did was freeze up my computer, because it played my audio like 1,000,000x over itself… But I figured out how to use Composer, and it’s working :slight_smile: Thanks!!