Event Structure

Hello all!

First of all: what a wonderful community you have here. The amount of information, tutorials and sample code available for free is astonishing.

My question relates to general code structure. Do most of you do all your game updates inside your event callbacks?
So, most of the game logic is called from inside the "OnScreenTouch" (for example) function?

Is there a way of harnessing a per-frame "Update" function or something? Is this a common way of doing things? Is it normal for the whole screen to have to redraw on a user's touch?

It looks to me that all of this stuff is abstracted away from the coder (the Corona animation stuff is super tidy).

Would be great if you guys could share some "best practices" with regards to this.

Many thanks!

Toby

Hey Toby - welcome to the community!

I'm glad you've been enjoying the amount of information and tutorials available :)

In my experience it's common practice to do any game updates inside of event callbacks, yes.

If you wanted to call something per frame that is also possible, you'd use a Runtime listener;

Runtime:addEventListener("enterFrame", functionName)

Does this help?

Peach :)

Yes. That is very useful indeed. Thank you!

I shall try and get used to the event based programming. :)

Just out of interest. Do you know what the performance hit would be, or maximum fps (say on an iPad1) one might get from moving all the game logic inside the Runtime listener?

Thanks,

Best Regards.

Hey Toby, glad I could help :)

I don't know for sure what the performance hit would be although I can imagine for a decent sized app, especially a game, it could be pretty extreme.

I've never written in another language so I don't know how hard it is to mentally make that switch but I can say I've found this event based stuff very intuitive. (Once I got started, anyway - at first it was all gibberish!)

Peach ;)

You should only run logic as and when it's needed. You don't have to have everything in a Runtime listener and not everything in a runtime listener has to be executed every frame.

Hope that helps ;)

views:1721 update:2012/2/10 9:26:24
corona forums © 2003-2011