1

好的。所以我正在编写一个 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
4

3 回答 3

0

你能描述更多关于你想要什么吗?使用 addEventListener 向我展示您的代码,并在所有侦听器中执行一些打印操作。因此,您可以追踪确切的问题在哪里。

于 2014-03-20T07:46:10.327 回答
0

检查这行代码:

background.y = _Ys

我认为应该是:

background.y = _H
于 2013-05-13T18:22:32.393 回答
0

我看不到您在哪里添加任何事件侦听器来捕获触摸或点击。我看到你在哪里移除水龙头处理程序。

尝试做:

一些图形:addEventListener(“点击”,loadHelp)

我只是无法从您的代码中看出您需要将事件侦听器附加到什么。

于 2013-05-27T01:45:37.650 回答