Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用corona sdk的简单lua游戏_Sdk_Lua_Coronasdk - Fatal编程技术网

使用corona sdk的简单lua游戏

使用corona sdk的简单lua游戏,sdk,lua,coronasdk,Sdk,Lua,Coronasdk,我试图写一个简单的corona SDK游戏,但我有一些问题。 我游戏中的抽签功能不能正常工作。 您可以在单击“开始”按钮之前进行绘制。 当你双击时,游戏就会崩溃 main.lua文件 display.setStatusBar( display.HiddenStatusBar ) --requiring libraries local physics = require ("physics") physics.start(true) physics.setGravity(0,9) --co

我试图写一个简单的corona SDK游戏,但我有一些问题。 我游戏中的抽签功能不能正常工作。 您可以在单击“开始”按钮之前进行绘制。 当你双击时,游戏就会崩溃

main.lua文件

display.setStatusBar( display.HiddenStatusBar )

--requiring libraries
local physics = require ("physics")
physics.start(true)
physics.setGravity(0,9)

  --constants
 local _W = display.contentWidth /2;
 local _H = display.contentHeight /2;

 -- game variables
local games = display.newGroup()
local orkHeight = 42;
local orkWidth = 40;
local score = 1;
local currentlevel;
local gameEvent = "";
local draw

--menu screen
local titleScreenGroup;
local titleScreen;
local playBtn;

--game screen
local background;
local goal;
local player;
local objective;

--Text box group
local objectiveText;
local levelText;
local levelNum;

 -- textBoxGroup
local textBoxGroup;
local textBox;
local conditionDisplay;
local messageText;


local bx, by=0, 0 -- Create our variables for drawing the line
local lines={}


local p=0
local e=0

function main()
    showTitleScreen();
end

function showTitleScreen()
    --alle title elementen in een groep ;p
    titleScreenGroup = display.newGroup();

    --background
    background = display.newImage("titleScreen.png")
    background.x = _W
    background.y = _H

    --play button
    playBtn = display.newImage("playButton.png")
    playBtn.x = _W;
    playBtn.y = _H + 50
    playBtn.name = "loadGame"

    --inserting 
    titleScreenGroup:insert(background)
    titleScreenGroup:insert(playBtn)

    --press button
    playBtn:addEventListener("tap", loadGame)   
end

--load actual game
function loadGame(event)
    if event.target.name == "loadGame" then
    transition.to(titleScreenGroup,{time = 0, alpha=0, onComplete =
    initializeGameScreen});
    playBtn:removeEventListener("tap", loadGame)
    end 
end

function initializeGameScreen()
    whiteBackground = display.newRect(0, 0, 480, 320)
    whiteBackground:setFillColor(255,255,255)

    player = display.newImage("ork.png")
    player.x = _W - 125
    player.y = _H - 50
    physics.addBody(player, "static", {density=0, bounce=.0, friction=.2})  

    --goto level 1 :)
    changelevel1()
end

function changelevel1()
    print("HOI")
    whiteBackground:addEventListener("tap", startGame)
end

function startGame()
draw:addEventListener("touch", drawALine)

drawALine(event)
end

function drawALine(event)

        if "began"==event.phase then
        bx, by=event.x, event.y -- Store the values, if you don't it starts from 0, 0

        elseif "moved"==event.phase then

       lines[p]=display.newLine(bx, by, event.x, event.y) -- Make a normal line
        --adding physics to the lines

        physics.addBody(lines[p], "static", {density=.2, friction=.0, bounce=0});
        --Width  
          lines[p].width=6 -- Just a boring old set width

        --color
          lines[p]:setColor(0,0,0)           


        bx, by=event.x, event.y -- Reset the bx and by, comment out for a "starburst" effect
        p=p+1
        e=e+1

        elseif "ended"==phase then

        end    


end




main()
我知道图片和东西不太合适,但我只是想做一个简单的游戏


提前感谢。

在我看来,只为显示对象添加了EventListener。在您的代码中没有绘制对象。因此,代码如下: 删除此行

draw:addEventListener(“触摸”,drawALine)

替换

Runtime:addEventListener(“touch”,drawALine)

并删除此行
drawALine(事件)

它对我有用

函数startName()
运行时:addEventListener(“touch”,drawALine)
--抽绳(活动)
结束


在我看来,addEventListener仅用于显示对象。在您的代码中没有绘制对象。因此,代码如下: 删除此行

draw:addEventListener(“触摸”,drawALine)

替换

Runtime:addEventListener(“touch”,drawALine)

并删除此行
drawALine(事件)

它对我有用

函数startName()
运行时:addEventListener(“touch”,drawALine)
--抽绳(活动)
结束