In order to work with touch events, we need to understand the event listener system within Corona. Learn up on it if you’re not familiar. It’s a dynamite read.
I went ahead and made some quick optimizations to the code by putting most of the animation sequence names into their own tables, and move around some sprite functions. Here’s how the code looks now:
I went ahead and made some quick optimizations to the code by putting most of the animation sequence names into their own tables, and move around some sprite functions. Here’s how the code looks now:
We’re working with touch listeners this time out, so I went ahead and created some functions that will handle sprite animation sequences. I also created a table holding the names of the image assets, which makes it a bit easier to create the buttons themselves.
A quick note on this code. I don’t like the widget.newButton APIs in Corona SDK. I started using them when they were super-buggy and I got out of the habit of using them in general. I code my own and it takes about 10 seconds longer than using a newButton.
Anyway, back to the code:
A quick note on this code. I don’t like the widget.newButton APIs in Corona SDK. I started using them when they were super-buggy and I got out of the habit of using them in general. I code my own and it takes about 10 seconds longer than using a newButton.
Anyway, back to the code:
I’m just including the function code above, with the entire project being available to download. Explaining a bit about what we’re working with here, we have the functions that are calling the animation sequence names from the table above.
We also have the self-rolled button logic, the touch listener and the code to create the buttons themselves. I’ve commented the functions themselves, but you’re going to see some basic information on sequence handling when the specific button is touched. Since i don’t like newButton widget logic, I made my own, but I didn’t use spritesheets for them. Why didn’t I use them? Mind your own business, that’s why.
Maybe I’ll use them in the future. Who can say. I did include some print statements that tell you the button you’re pressing and the buttonPress phase. The buttonPressed phase is what allows you to press a button in general. The runType variable is what tells the firing function whether it can run or not, and the weaponEquipped variable handles, obviously, which weapon is equipped.
TL;DR? Check the download link below for the full project so far:
Platformer project
We also have the self-rolled button logic, the touch listener and the code to create the buttons themselves. I’ve commented the functions themselves, but you’re going to see some basic information on sequence handling when the specific button is touched. Since i don’t like newButton widget logic, I made my own, but I didn’t use spritesheets for them. Why didn’t I use them? Mind your own business, that’s why.
Maybe I’ll use them in the future. Who can say. I did include some print statements that tell you the button you’re pressing and the buttonPress phase. The buttonPressed phase is what allows you to press a button in general. The runType variable is what tells the firing function whether it can run or not, and the weaponEquipped variable handles, obviously, which weapon is equipped.
TL;DR? Check the download link below for the full project so far:
Platformer project