我对Lua是新手,目前正在从事一个名为“红对蓝”的项目。它基本上是两个队,红队和蓝队,它的作用是一个记分板。如果我点击左边,红色得到1分。如果我点击蓝边,蓝色得到一分。屏幕分辨率为320 x 480,但它根据设备的不同而变宽。下面是一个截图:http://i40.tinypic.com/5lqosk.jpg
这是我的密码:
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是用作传感器的空白图片。
发布于 2013-12-30 16:38:56
如果您想缩放图片,使其始终与屏幕的一半完全匹配,请执行以下操作:
--[[
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
若要在触摸框时更新记分板,请将事件侦听器结构如下:
local function redt( event )
redscore = redscore + 1;
redtext.text = tostring(redscore)
return true
end
redc:addEventListener( "tap", redt )
重复蓝色盒子。你还想用它做什么?
https://stackoverflow.com/questions/20837662
复制相似问题