Multi-touch is a very useful feature for games and mobile apps and comes frees of charge in native applications, but how do you use it in CoronaSDK?
Its simpler than one can imagine.
On your main.lua add the following activation codeline
With this your "touch" listener will have more than one touch in its event variable, an id property is available to identify each different touch.
Ok but it would not be me posting if I let you guys with only that ummm lets say dumb tip.
To try it out create a blank project with a new main.lua and our multitouch activation.
Let us place two round buttons to control a ball that will move it horizontally and vertically when these buttons are pressed. Also add a name variable with a differente identifier for each button, we will use it to know when each one has been touched.
You're probably seeing something similar to this
Now to the moving part.
Create a function for listening the touch actions and add it to both buttons.
When you execute it in the CoronaSDK Simulator one thing will come to mind: "How the hell I test it if I can only use single touches?"
Yes my friend that is an annoying problem, you will have to build your application and test it directly into your device. If you don't have one I suggest you to check if corona ultimote or luaglider (cider) have anything useful on this case.
Happy touching.
Mostrando postagens com marcador corona sdk. Mostrar todas as postagens
Mostrando postagens com marcador corona sdk. Mostrar todas as postagens
segunda-feira, 29 de outubro de 2012
quarta-feira, 11 de julho de 2012
Using sprite sheets in CoronaSDK
A thing that is very common and useful in game development is the application of sprite sheets. Most of us make of this a day-to-day tool, but some don't know what it is or how to use it depending on the platform or because of any other problem.
So before we start I'm going to give quick defs.
- Sprite - its the assets representing an image in your game. Like an 1up mushroom from SMB.
- Sprite Sheet - its a group of sprites in a single file, can represent various animations or simply a group of static images used in the game. Like the zero sprite sheet bellow.
For the first demo we're going to use a classic character the jelly!
The jelly sprite sheet is equally divided, that way we don't need to care about specifying each frame individual settings.
Start importing the sprite classes from CoronaSDK, they are required to our code.
Each jelly sprite has 37x47 and we have 16 frames on our sheet so Corona needs to be informed of this, for that purpose we use a simple lua table.
Now we can call the graphics.newImageSheet using the sprite sheet filename and our table.
So we have our sheet with a few lines, now we need to specify the frames we want to display and create the image onscreen.
If you run now the simulator now the jelly will appear correctly in the screen but won't animate. Try to add sprite:play() after the scaling code line and watch our jelly flick like craze in the screen.
Lets improve our sample and change our animationData table to the following
Now our jelly feels more "natural". Why is that?
That happened when we added a time for our "walking_down" animation, if you play with it you can speed it up/down, don't forget that the time is given in miliseconds.
Still we can't switch between animations.
For that purpose we need to improve our code with a couple of lines. Begin changing the animationData to
And to see the changes add some touch logic after the sprite:play() call (in fact you can even replace it)
When you touch left or right of our jelly sprite you'll see it change bettwen walking_left and walking_right animations. That was achieved using sprite:setSequence("animation_name") method.
After calling setSequence on a sprite is necessary to call play() if you want it to run the animation otherwise it will switch to the first frame (start parameter for example) and stay still.
Now it feels better uh, but wait! What if we move our jelly while animating?
Insert a transition call after onTouch sprite:play() line like that:
With these basic steps you added a sprite from a sprite sheet in the screen and made it move left and right.
Hey but it isn´t over yet! When the sprite sheet is like zero sample (from megaman, remeber?) we have to use more complex info on sheetSettings variable and also when we have non sequential animation we need to be more specific on our animationData variable.
Using short samples our animationData could have it walking_left animation re-written to
What we did here is jump through frames 5,2,7 and 3 always in that order for 800ms 2 times.
And to keep things simple, instead of given a gigantic sheet lets imagine sheetSettings can be re-written with every frame of our green jelly that we already know.
Even though this is useless in this case, we can use it for more complex sprite sheet images.
Last question before letting you code for yourself: How the hell am I supposed to build these sheets?
Well you can use some useful tools, let me give 2 hints:
- Texture Packer
- Zwoptex
Leave your questions and thoughts and happy coding!!
So before we start I'm going to give quick defs.
- Sprite - its the assets representing an image in your game. Like an 1up mushroom from SMB.
- Sprite Sheet - its a group of sprites in a single file, can represent various animations or simply a group of static images used in the game. Like the zero sprite sheet bellow.
For the first demo we're going to use a classic character the jelly!
The jelly sprite sheet is equally divided, that way we don't need to care about specifying each frame individual settings.
Start importing the sprite classes from CoronaSDK, they are required to our code.
Each jelly sprite has 37x47 and we have 16 frames on our sheet so Corona needs to be informed of this, for that purpose we use a simple lua table.
Now we can call the graphics.newImageSheet using the sprite sheet filename and our table.
So we have our sheet with a few lines, now we need to specify the frames we want to display and create the image onscreen.
If you run now the simulator now the jelly will appear correctly in the screen but won't animate. Try to add sprite:play() after the scaling code line and watch our jelly flick like craze in the screen.
Lets improve our sample and change our animationData table to the following
Now our jelly feels more "natural". Why is that?
That happened when we added a time for our "walking_down" animation, if you play with it you can speed it up/down, don't forget that the time is given in miliseconds.
Still we can't switch between animations.
For that purpose we need to improve our code with a couple of lines. Begin changing the animationData to
And to see the changes add some touch logic after the sprite:play() call (in fact you can even replace it)
When you touch left or right of our jelly sprite you'll see it change bettwen walking_left and walking_right animations. That was achieved using sprite:setSequence("animation_name") method.
After calling setSequence on a sprite is necessary to call play() if you want it to run the animation otherwise it will switch to the first frame (start parameter for example) and stay still.
Now it feels better uh, but wait! What if we move our jelly while animating?
Insert a transition call after onTouch sprite:play() line like that:
With these basic steps you added a sprite from a sprite sheet in the screen and made it move left and right.
Hey but it isn´t over yet! When the sprite sheet is like zero sample (from megaman, remeber?) we have to use more complex info on sheetSettings variable and also when we have non sequential animation we need to be more specific on our animationData variable.
Using short samples our animationData could have it walking_left animation re-written to
What we did here is jump through frames 5,2,7 and 3 always in that order for 800ms 2 times.
And to keep things simple, instead of given a gigantic sheet lets imagine sheetSettings can be re-written with every frame of our green jelly that we already know.
Even though this is useless in this case, we can use it for more complex sprite sheet images.
Last question before letting you code for yourself: How the hell am I supposed to build these sheets?
Well you can use some useful tools, let me give 2 hints:
- Texture Packer
- Zwoptex
Leave your questions and thoughts and happy coding!!
Marcadores:
corona sdk,
game development,
lua,
sprite,
sprite sheet
sexta-feira, 27 de maio de 2011
I want to use Lua....but what about the IDE?
I think that the title said it all, you look to Lua as a good language to create whatever you're planning to, but then you face a neat problem: The IDE.
This post is dedicated to Lua devs and game devs, specially those that decided to use Corona SDK as an application platform (more game SDK than app SDK).
The steps to follow are:
This post is dedicated to Lua devs and game devs, specially those that decided to use Corona SDK as an application platform (more game SDK than app SDK).
The steps to follow are:
- Download and install IntelliJ Community Edition or pay for other versions (is not really necessary if you don't really need) from here http://www.jetbrains.com/idea/download/index.html
- Download Lua plugin for IntelliJ here http://plugins.intellij.net/plugin/?idea_ce&id=5055
- Now unzip Lua plugin and copy IDLua folder to intelliJ's plugin folder in a path like this C:\Program Files (x86)\IntelliJ IDEA Community Edition 10.5\plugins (is very likely that your folder path is another one)
- Open IntelliJ and access Settings in the file menu or type Ctrl+Alt+S. In IDE Settings section you'll see the Plugins area, click it and check if Lua is listed on the right panel. If isn't appearing there try to install trough available list or follow this tutorial https://bitbucket.org/sylvanaar2/lua-for-idea/wiki/Home
- Hey its done!!! When you start project creation you'll see Lua option in the list...
Now for Corona SDK
- Download the Corona SDK for IntelliJ here https://bitbucket.org/sylvanaar2/idlua-sdk-corona/wiki/Home
- Unzip the package into a fixed place, this means that this folder (Corona SDK for IntelliJ) must remain there as long as you're using it with the IDE
- After creating the project you will work into select project's root and type F4 to access project structure.
- Here click in SDKs in Platform Settings section and in Lua sdk add a new Classpath, in this case the path to your Corona SDK fixed folder.
- Ready to rumble!!! Now you have intellisense for Corona code and the documentation (type ctrl+q to access it)
If you have any problems adding sdk's and api's follow the tutorials bellow or email me: vitor dot navarro87 at gmail dot com
Marcadores:
corona sdk,
engine,
game development,
IDE,
IntelliJ,
JetBrains,
lua
Assinar:
Postagens (Atom)


