Archive

Posts Tagged ‘app’

Implementing a Game Center button in your Corona SDK Game.

June 13th, 2011 6 comments

I’ve been trying to figure out how to do a Game Center button for my game and be able to link to the Game Center leaderboards and achievements directly from my Corona SDK based game.

I had not found much information on the Internet on how to do this. Most examples were involving Objective C using Xcode and adding the Game Center framework to the game, then calling relevant methods from the framework.

I basically gave up on the idea about connecting directly to the leaderboards and decided to just try and launch the Game Center app from my game.

Here is the code I used (mostly lifted from Jayant C Varma’s “rating.lua” file found on the Corona SDK site):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local function testNetworkConnection()
local netConn = require('socket').connect('www.apple.com', 80)
if netConn == nil then
return false
end
netConn:close()
return true
end
    
local function gotoGameCenter()
local device = system.getInfo ( "environment" )
local appURL = "gamecenter:"
if device == "simulator" then
print ( "Cannot spawn this URL in the simulator" )
else
if testNetworkConnection() then
system.openURL ( appURL )
end
end
end
local gameCenterButton = ui.newButton{defaultSrc="gamecenterbtn.png", defaultX = 164, defaultY = 32, onRelease=gotoGameCenter}
gameCenterButton.x = display.contentWidth / 2
gameCenterButton.y = 110
highScores:insert(gameCenterButton)

And much to my surprise, it works like a charm. Now to track down those pesky specific URL’s…. I should note, this is a new addition to my game and it has not been submitted to Apple yet. No warranties expressed or implied.

Implementing a Health Status Bar in Corona SDK

May 30th, 2011 No comments

Implementing a Health Status Bar in Corona SDK

Many games need a way to show the players how well they are doing. It could be a simple counter to show the number of lives left or a bar that decreases and increases as a players energy goes up and down.

There are as many different ways to do this as there are games but lets look at a couple of different ways.

The simplest may be simply using text to display the health status:

1
2
3
4
5
local lives = 5
local livesLabel = display.newText("Lives: ", 10, 30, native.systemFont, 16)
local livesValue = display.newText(string.format("%d", lives), livesLabel.contentWidth+20,30,native.systemFontBold, 16)
livesLabel:setTextColor(225,225,225)
livesValue:setTextColor(255,255,255)

Then later in your code when a player looses a life (or gains one back) simply change the text value of “livesValue” and Corona will magically update the value for you:

1
2
3
4
if lives > 0 then
lives = lives - 1
end
livesValue.text = string.format("%d", lives)

Of course you might want to drop a graphic behind the text, set the colors accordingly, and possibly drop a duplicate text string underneath offset by a pixel to give a little stroke/shadow to the text.

But our players expect more from games and a simple text display won’t be accepted as high quality. Traditional arcade games have shown your lives as small versions of your player’s graphic. If your game involves a ship, perhaps you see a display of 5 little ships to show your life count.

With a display of say 5 small rockets, you will need one image and you will replicate it several times.

1
2
3
4
5
6
7
8
9
local lifeIcons = {}
local lives = 5
local maxLives = 5
local i
for i = 1, maxLives do
lifeIcons[i] = display.newImage("lifeicon.png")
lifeIcons[i].x = 10 + (lifeIcons[i].contentWidth * (i - 1))
lifeIcons[i].y = 30 -- start at 10,10
end

This will create a display of 5 little icons that shows your full life status. Later in your code when you need to change the display:

1
2
3
4
if lives > 0 then
lifeIcons[lives].isVisible = false
lives = lives - 1
end

Later when you need to give a life back:

1
2
3
4
5
lives = lives + 1
if lives > maxLives then
lives = maxLives
end
lifeIcons[lives].isVisible = true

But what if you want more of a bar-graph display. As long as you’re using discrete values, you can continue to use a similar method using different graphics for each value, in this example, there are 5 lives, so you can create 5 different graphics for each of the 5 life states.


Instead of using a loop to load in the same graphic, you would need to load in each of the separate five graphics in and position them all at the same location:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
local lifeIcons = {}
local lives = 5
local maxLives = 5
lifeBar[0] = display.newImage("lifeicon0.png")
lifeBar[1] = display.newImage("lifeicon1.png")
lifeBar[2] = display.newImage("lifeicon2.png")
lifeBar[3] = display.newImage("lifeicon3.png")
lifeBar[4] = display.newImage("lifeicon4.png")
lifeBar[5] = display.newImage("lifeicon5.png")
local i
for i = 1, maxLives do
lifeBar[i].x = 10
lifeBar[i].y = 30
lifeBar[i].isVisible = false
end
lifeBar[lives].isVisible = true

Then to change the graphic:

1
2
3
4
5
if lives > 0 then
lifeBar[lives].isVisible = false
lives = lives - 1
lifeBar[lives].isVisible = true
end

This same concept can be done with MovieClips.

1
2
3
4
healthSprites = movieclip.newAnim{"lifeicon1.png", "lifeicon2.png", "lifeicon3.png", "lifeicon4.png", "lifeicon5.png", "lifeicon0.png"}
healthSprites.x = 50
healthSprites.y = 10
healthSprites:play{startFrame=1, endFrame=lives, loop=1, remove=false}

Then to show the current health level:
[/crayon]

lives = lives – 1
if lives < 0 then
lives = 0
end
if lives == 0 then
healthSprites:play{startGrame=6, endFrame=6, loop=1, remove=false}
else
healthSprites:play{startFrame=1, endFrame=lives, loop=1, remove=false}
end
[/crayon]

This gives you the benefit of a little animation as well. Unlike the example above, we load in the “No life left” graphic in frame 6, because movieclip starts at frame 1. We could have put frame 0 first, and just done a “lives + 1″ to get the right offset.

Hope this is helpful!

 

Review of the RIM BlackBerry Twitter App

April 9th, 2010 1 comment

My life as a BlackBerry owner has seen me through three handsets. I started with a Verizon 8703e, a reasonably functional handset. The browser was terrible and there were not a lot of apps for it. TwitterBerry was my app of choice early in its infancy. But as the developer’s added features (including fetching 200 tweets) it became unusable.

A short term acquaintance with a Pearl 8130 allowed me to browse the Internet better yet TwitterBerry didn’t seem to run well. I switched to TwiXtreme, which seemed to run better. I never got into hand held tweeting with that handset, partially because of the half-keyboard, the other part was the small screen and the apps still did not perform well.

In January of this year, I inherited a Curve 8900 on the AT&T network. I installed TwiXtreme, but again, just couldn’t get into twittering from my hand-held, though it was a nice “cute” app.

Today, I installed the office Research In Motion Twitter Application available from the BlackBerry App World. It installed quickly. I added my twitter login and password, said to remember me and it was off an running.

The app has all the usual features, see your mentions, direct messages and lets you reply to messages, set your status and so on. It does it fast and elegantly. Though it only shows two tweets at a time, it very easily scrolls to older tweets and if its fetching older tweets in the background you don’t see any delay.

It also supports lists, popular topics and search, something not seen in the other apps I’ve tried. And like any good Twitter app, it counts down your available number of characters as you compose your tweets.

Where the RIM Twitter client has impressed me is how it fits in with the Blackberry. You are notified when new tweets arrive (a feature I turned off), when new mentions and direct messages show up along with the rest of your messages. Now, e-mail, FaceBook messages, gTalk notifications, and important Twitter notifications all flow through a single messaging interface.

It also interfaces well with the camera and stored photos. I can initiate a photo from the Twitter app or I can grab an existing photo from my memory card and tweet it out using TwitPic in a very seamless manner.

It is supposed to shorten URL’s, but I’ve not had a chance to test it yet. We will also have to see what the impact on the battery will be with it running in the background all the time.

Pending the battery tests, this looks like one very well done application and its supposedly an open Beta. My version is 1.0.0.37.

At this point, I’d have to give it a thumbs up and recommend others give it a go. Twitter on the hand-held might become fun again.

Categories: Tech Geek Tags: , , , , ,