首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >简单的Corona应用程序-触摸事件

简单的Corona应用程序-触摸事件
EN

Stack Overflow用户
提问于 2013-12-30 10:28:36
回答 1查看 317关注 0票数 1

我对Lua是新手,目前正在从事一个名为“红对蓝”的项目。它基本上是两个队,红队和蓝队,它的作用是一个记分板。如果我点击左边,红色得到1分。如果我点击蓝边,蓝色得到一分。屏幕分辨率为320 x 480,但它根据设备的不同而变宽。下面是一个截图:http://i40.tinypic.com/5lqosk.jpg

这是我的密码:

代码语言:javascript
运行
复制
display.setStatusBar(display.HiddenStatusBar);
local redscore = 0
local bluescore = 0
local background = display.newImage("images/background.png");
local redc = display.newImage("images/redc.png", 0, 0);
local bluec = display.newImage("images/bluec.png", 240, 0);
local redtext = display.newText(redscore, 55, 100, native.systemFont, 32*4);
local bluetext = display.newText(bluescore , 290, 100, native.systemFont, 32*4);

local function redt( event )
    redscore = redscore + 1;
    return true
end
redc:addEventListener( "tap", redt )

local function bluet( event )
    bluescore = bluescore + 1;
    return true
end
bluec:addEventListener( "tap", bluet )

redc和bluec是用作传感器的空白图片。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-30 16:38:56

如果您想缩放图片,使其始终与屏幕的一半完全匹配,请执行以下操作:

代码语言:javascript
运行
复制
--[[
    Take half the width of the device and adjust for larger screens, dividing by
    the current width of the picture to produce the value it needs to be scaled
    by to fit
]]
local wScale = ((display.layoutWidth/2) - display.screenOriginX) / redc.contentWidth

--Do the same for the height
local hScale = ((display.layoutHeight/2) - display.screenOriginY) / redc.contentHeight

--Scale the image
redc:scale(wScale,hScale)

--[[
    Position the image. Since the default is a central reference point, you take half of              
    the image's width/height and add the adjustment for larger screens
]]
redc.x = (redc.contentWidth/2) + display.screenOriginX
redc.y = (redc.contentHeight/2) + display.screenOriginY

若要在触摸框时更新记分板,请将事件侦听器结构如下:

代码语言:javascript
运行
复制
local function redt( event )
    redscore = redscore + 1;
    redtext.text = tostring(redscore)
    return true
end
redc:addEventListener( "tap", redt )

重复蓝色盒子。你还想用它做什么?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20837662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档