Corona – Eight elements of a successful game
This article could go beyond Corona. Some of the ideas here could apply to a lot of things.
http://blog.anscamobile.com/2011/03/eight-elements-to-a-successful-game/
This article could go beyond Corona. Some of the ideas here could apply to a lot of things.
http://blog.anscamobile.com/2011/03/eight-elements-to-a-successful-game/
Corona makes it easier than anything to get sound into a project. The documentation says:
Sound Formats
So it looks like you can use wav, mp3, caf and aac on IOS. Since I’m focusing on the IOS platform I’ll stick with one of these formats. You can use garage band to generate AAC and MP3 files.
To get a sound to play you need to load the file creating a reference to the audio object in the process. Then tell that audio object to play.
Try it for yourself. Create a new Corona project, follow these steps:
Add the following Lua code to your main.lua file. The file I for the example was named beep.mp3. Be sure to replace this name with the name of your sound file.
local mySound = audio.loadSound( "beep.mp3" ) audio.play( mySound )
Pretty simple huh? The first line loads your sound. The next line tells the sound to play.
Custom menus are a great options for WordPress. A menu is basically a list of links. This list of links can appear anywhere in your theme. You can customize the links that appear in the list via the admin panel.
A theme may contain as many custom menus as you care to add. Each can be customized through the admin panel. Custom menus can appear anywhere in your site you care to place them.
To get started create a function.php file in your theme folder. Next add a <?php ?> tag to your functions.php file. Your functions.php should contain one <?php ?> tag and all of the custom php code should go between the <?php and ?>.
Now add the code to generate a new custom menu. Add the following inside the <?php and ?>:
// Notify WordPress that you want to run a function when the page initializes
add_action( 'init', 'register_my_menus' );
// Here's the function
function register_my_menus() {
// Call this function to register a new menu
// Declare a slug-name and a display name for the new menu
register_nav_menus(
array('header-menu' => __( 'Header Menu' ) )
);
}
The first line tells WordPress to call on the function resgister_my_menus when the page initializes. The register_my_menus function is defined below. This functions calls on register_nav_menus, which is defined by WordPress. This function receives an Array describing the menu to create.The menu gets two names. A slug name which is used in code to refer to the menu. The other is a display name which is used when the name appears in a page.
The __() function used to wrap the display name, as in __(‘Header Menu’) is a special function used translate your page in to other languages. See the codex for more information. This function is not required but is good practice to include.
For more info refer to the codex: http://codex.wordpress.org/Function_Reference/wp_nav_menu
The functions.php file is a file that can be ioncluded in anything theme you might create for WordPress. This file is used to add unique functions to your WordPress theme. The functions.php file you can add new functionality to your site and modify the regular functions of WordPress. You can also gain access to many features of WordPress that are not available through the admin panel.
To use functions.php just create a plain text file named functions.php and add it to your theme folder. From here you will code that file that adds features to your theme.
Note: Every theme will have it’s own functions.php file and the features added by that file will only be in effect when that theme is active.
A variable is a storage space for a value that your program will use.Imagine you are creating a game. You might want to keep track of the game score. You would use a variable to do this. Often your programs will have many variables that refer to lots of different things.To assign a variable a value use the equal sign. For example:
score = 0
You can think of variables in the same way that you used x and y in algebra. These letters were placeholders for many possible values. In Lua, like many other programming languages variables get a name. The name can be any combination of characters. You can use variables as placeholders for values that will change as your program runs. For example you might display your score by setting the text property of a Text Object. For example:
scoreText = display.newText(...) score = 0 -- later in your program scoreText.text = score
Variables are called variables because the stored values can change. As your program runs you can change the value assigned to a variables. You can assign a new value at anytime to a variable using the equal sign.
The example above declares two variables scoreText and score. The first holds a reference to a new Text Object. The second holds a number, 0 in this case.
score = 10000
Note: Lua doesn’t support composite assignment operators like += and -=. Instead you’ll need to use:
score = score + 100
In Lua variables can be Global or Local. All variables are Global unless specifically declared as Local. Global variables can be accessed anywhere in the program. Local variables can only be accessed in the code block where they were declared. Declare a Local variable with the key word “local” the first time it appears. For example:
core = 100 local color = "red"
Here “score” is a global variable and color is a local variable.
Scope is a term that refers to where a variable can be accessed. The scope Global variables is easy to determine. Since they are accessible everywhere.
Local variables on the other hand take a little more thought. Unlike global variables, local variables have their scope limited to the block where they are declared. A block is the body of a control structure, the body of a function, or a chunk (the file or string with the code where the variable is declared).
x = 10 -- global variable local i = 1 -- local to the chunk while i<=x do local x = i*2 -- local to the while body print(x) --> 2, 4, 6, 8, ... i = i + 1 end if i > 20 then local x -- local to the "then" body x = 20 print(x + 2) else print(x) --> 10 (the global one) end print(x) --> 10 (the global one)
It is good programming style to use local variables whenever possible. Local variables help you avoid cluttering the global environment with unnecessary names. Moreover, the access to local variables is faster than to global ones.