在科罗娜SDK我怎样才能把比分门将到我的应用程序? [英] In Corona SDK how can I put a score keeper into my app?

查看:211
本文介绍了在科罗娜SDK我怎样才能把比分门将到我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我正在游戏到1分每球击中桨。(它的一个乒乓球比赛)我也喜欢游戏,以节省时间榜增添了比分。这是我还没有取得比赛的唯一元素。如果有人能够帮助这将是巨大的。

I want the game I'm making to add 1 point to the score every time the ball hits the paddle.(its a pong game) I would also like the game to save highscores. This is the only element of the game I haven't made yet. If anyone could help that would be great.

推荐答案

您可以解决你的问题,一个更简单的方法。

You can solve your problem in a easier way..

只是声明一个变量为这样的分数..

Just declare a Variable for the Score like this..

本地分数= 0

然后加1的比分变量时,它打桨。因此,在插入冲突功能的编码下面给出:

Then Increment the score variable by 1 whenever it hits the paddle. So Insert the coding in Collision Function as given below:

local function onCollision(event)
{
score=score+1
}
ball.collision=onCollision
ball:addEventListener("collision",ball)

最后,当你需要保存你的高分(GAMEOVER后),您可以使用preference而不是JSON,这使得较大的编码。

Finally When you need to save your highscore (after gameover), You can use Preference instead of json which makes the larger coding.

local preference= require "preference"
local highscore=0

preference.save{highscore=score}

如果你想显示高分,然后使用以下内容:

If you want to display the Highscore, then use the following:

highscore_value=preference.getValue("highscore")
display.newText(highscore_value,0,0,nil,30)

这可能是您的问题!

这篇关于在科罗娜SDK我怎样才能把比分门将到我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆