Tuesday, July 17, 2012

Android Game Development and Corona SDK Notes Part 1 - Introduction


What 2d game engines are there for android? You can always develop a game from scratch using google's sdk but maybe there's an easier way to do it even if it requires a little cash.

A game engine is a tool that facilitates creating games. Most of them require at least some coding. 

Some Android Game Engines:

* Cocos2D
Looks to be a little out of date. Last update was in 2011.
* Corona SDK
It has an api and uses the lua programming language.
* Andengine
Open source, looks to require java coding.
* Unity
From a little research this requires some coding from time to time.

Let's explore the Corona SDK a little bit.

Creating a new project requires editing  main.lua

How to set the background image

local bg = display.newImage( "someimage.png" )

Now we want to overlay an image and display text so it fits in this new image.

If we want to display an image in a specific spot:

local box = display.newImage("box.png",0,380)

That puts an image at position x = 0 y= 380

You can display text over that box like this:

local sometext = display.newText( "Message here", 22, 400, native.systemFont, 17 )
sometext:setTextColor( 0, 0, 0 )

You can add a listener to an image:

First define the listener, define the image and assign the listener to it:

local selectSquare = function( event )
local t = event.target
local phase = event.phase

if "began" == phase then
print( "selected square" )
end

-- Stop further propagation of touch event
return true
end


local sq= display.newImage( "square.png" )
sq.x=148
sq.y=55
sq:addEventListener( "touch", selectSquare) 

Now whenever you press the image it prints "selected square" in the console window.

So far Corona doesn't look too bad so far. I like how fast and easy it is to see changes in the simulator.

I plan explore the api bit more in the next part.


No comments:

Post a Comment