为什么我的文字没有显示corona sdk

时间:2016-06-05 17:07:04

标签: lua corona

我花了2天时间试图找出问题,但我不能这样问我 myText变量没有显示它是假设说得分我知道我没有更新分数但是没有关系 继承人代码:

  display.setStatusBar( display.HiddenStatusBar )
-- Start Physics
local physics = require("physics")
physics.start()
-- Set Variables
_W = display.contentWidth; -- Get the width of the screen
_H = display.contentHeight; -- Get the height of the screen
motionx = 0; -- Variable used to move character along x axis
motiony = 0; -- Variable used to move character along y axis
speed = 2; -- Set Walking Speed
jump = 3;-- set jumping speed
score=0;
local myText = display.newText(score,_W-20,_H-20, native.systemFont, 30 )
-- Add Sky to the background
local sky = display.newImage("background_sky.png")
sky.x = _W/2; sky.y = 160;
-- add platform1 to game
local platform1 = display.newImage( "grass.png")
platform1.width=100;platform1.height=20;platform1.x=150;platform1.y=_H/2;
physics.addBody(platform1,"static",{ friction=0.5, bounce=0.3 })
-- add platform2 to game
local platform2 = display.newImage( "grass.png")
platform2.width=100;platform2.height=20;platform2.x=350;platform2.y=_H/2-70;
physics.addBody(platform2,"static",{ friction=0.5, bounce=0.3 })

-- Add Grass floor to game
local grass_bottom = display.newImage( "grass_bottom.png")
grass_bottom.x = _W/2; grass_bottom.y = _H-35;
--grass_bottom:setReferencePoint(display.BottomLeftReferencePoint)
physics.addBody( grass_bottom, "static", { friction=0.5, bounce=0.3 } )

-- Add Grass to the background
local grass_top = display.newImage( "grass_top.png")
grass_top.x = _W/2; grass_top.y = _H-95;

-- Add Guy
local guy = display.newImage( "guy.png" )
physics.addBody( guy, "dynamic", { friction=0.5, bounce=0 } )
guy.x = 2; guy.y = 150;

-- Add left joystick button
local left = display.newImage ("btn_arrow.png")
left.x = 45; left.y = 280;
left.rotation = 180;

-- Add right joystick button
local right = display.newImage ("btn_arrow.png")
right.x = 120; right.y = 282;
-- add up joystick button
local up = display.newImage ("btn_arrow.png")
up.x = 195;up.y=280;
up.rotation=-90;

-- Stop character movement when no arrow is pushed
local function stop (event)
    if event.phase =="ended" then
        motionx = 0;
        motiony = 0;
    end
end
Runtime:addEventListener("touch", stop )

-- Move character
local function moveguy (event)
    if guy.x < _W - 2 then
     if guy.x > 2 then
    guy.x = guy.x + motionx;
    guy.y = guy.y - motiony;
    end
         if guy.x == 2 then
    guy.x=3;
    end
if guy.x < 2 then
    guy.x=3;
    end
    if guy.x < _W - 2 then
    guy.x = guy.x + motionx;
    guy.y = guy.y - motiony;
    end
    if guy.x == _W - 2 then
    guy.x=_W-3;
    end
    if guy.x > _W - 2 then
    guy.x=_W-3;
    end

end
    end
Runtime:addEventListener("enterFrame", moveguy)

-- When left arrow is touched, move character left
function left:touch()
    motionx = -speed;
end
left:addEventListener("touch",left)

-- When right arrow is touched, move character right
function right:touch()
    motionx = speed;
end
right:addEventListener("touch",right)
-- When up arrow is touched, move character up
function up:touch()
    motiony = jump;
end
up:addEventListener("touch",up)

只是那一行

local myText = display.newText(score,_W-20,_H-20, native.systemFont, 30 )

我尝试了我需要你帮助的一切

2 个答案:

答案 0 :(得分:1)

不是电晕专家,但我在图形/ GUI编程方面有相当丰富的经验。

对我而言,添加背景时添加文本看起来很奇怪。这会导致到目前为止我使用过的所有框架都存在问题。

想象一下,你想在路上画一辆车。如果你先画汽车,你会在汽车上画路。你最终得到了一张道路的照片......

只是一个猜测。也许电晕足够聪明,可以自动将文本放入顶层。但我觉得很难相信。

答案 1 :(得分:0)

您的文字显示在背景后面,因为之前已创建。我建议使用组来创建背景,中间和前层,然后创建场景的显示对象并将它们添加到您想要的组中。