确定。所以我正在编写一个Corona程序,在书中我按照所有说明创建了一个菜单并创建了一个新的游戏场景。问题是当我把代码放入模拟器或bluestacks android并按下图片没有任何反应时没有任何反应。没什么,跟帮助按钮一样。
我做错了什么?这是我的代码:
function loadGame(event)
if event.target.name == "playbutton" then
transition.to(menuScreenGroup, {time = 0, alpha=0, onComplete = addGamescreen})
playBtn:removeEventListener("tap", loadgame)
end
end
function loadHelp(event)
if event.target.name == "helpbutton" then
transition.to(menuScreenGroup, {time = 0, alpha=0, onComplete = addHelpScreen})
helpBtn:removeEventListener("tap", loadHelp)
end
end
function addHelpScreen()
helpScreenGroup = display.newGroup()
helpScreen = display.newImage("helpScreen.png", 0, 0, true)
helpScreen.x = _W
helpScreen.y = _H
end
function addGameScreen()
background = display.newImage("bg.png", 0, 0, true)
background.x = _W
background.y = _Ys
paddle = display.newImage("paddle.png")
paddle.x = 160; paddle.y = 460;
paddle.name = "paddle"
ball = display.newImage("ball.png")
ball.x = 160; ball.y = 460;
ball.name = "ball"
scoreText = display.newText("Score:", 5, 2, "Arial", 14)
scoreText:setTextColor( 255, 255, 255, 255)
scoreNum = display.newText("0", 54, 2, "Arial", 14)
scoreNum:setTextColor( 255, 255, 255, 255)
levelText = display.newText("Level:", 420, 2, "Arial", 14)
levelText:setTextColor(255, 255, 255, 255)
levelNum = display.newText("1", 460, 2, "Arial", 14)
levelNum:setTextColor( 255, 255, 255, 255)
gameLevel1()
currentLevel = 1
bricks:toFront()
local numOfRows = 4
local numOfColumns = 4
local brickPlacement = {x = (_W) - (brickWidth * numOfColumns ) / 2 + 20, y = 50}
for row = 0, numOfRows - 1 do
local brick = display.newImage("brick.png")
brick.name = "brick"
brick.x = brickPlacement.x + (column * brickWidth)
brick.y = brickPlacement.y + (row * brickHeight)
physics.addBody(brick, "static", {density = 1, friction = 0, bounce = 0})
bricks.insert(bricks, brick)
end
end
function gameLevel2()
currentLevel = 2
bricks:toFront()
local numOfRows = 5
local numOfColumns = 8
local brickPlacement = {x = (_W) - (brickWidth * numOfColumns ) / 2 + 20, y = 50}
for row = 0, numOfRows - 1 do
for column = 0, numOfColumns - 1 do
-- Create a brick
local brick = display.newImage("brick.png")
brick.name = "brick"
brick.x = brickPlacement.x + (column * brickWidth)
brick.y = brickPlacement.y + (row * brickHeight)
physics.addBody(brick, "static", {density = 1, friction = 0, bounce = 0})
bricks.insert(bricks, brick)
end
end
end
答案 0 :(得分:0)
检查以下代码行:
background.y = _Ys
我认为应该是:
background.y = _H
答案 1 :(得分:0)
我没有看到你在哪里添加任何事件监听器来捕获触摸或点击。我看到你要删除点击处理程序的位置。
尝试做:
somegraphic:的addEventListener( “抽头”,loadHelp)
我无法从你的代码中知道你需要将事件监听器附加到什么地方。
答案 2 :(得分:0)
你能描述一下你想要什么吗?用addEventListener向我展示你的代码,并在所有的监听器中做一些打印。因此,您可以追踪确切问题的位置。