LUA:没有创建场景。怎么了?

时间:2016-10-18 16:01:52

标签: lua corona transition

我正在构建一个游戏,我有一个开始屏幕并点击开始按钮,它应该把我带到第一级。有些东西发生了,然后我将被带到第二级。

然而,我遇到了问题而无法找到解决方案。 当我点击开始按钮时,它似乎陷入了创建功能,因为我打印出一些东西。我被告知你不必在创建功能中放置任何东西,只需将所有内容放在SHOW FUNCTION中。我误导了吗?

START SCENE

local composer = require("composer")
local widget = require("widget")

local options = {effect = "fade", time = 800}
local startBtn;

local function start(event)
    -- load first scene
    composer.gotoScene( "level1", options);
    startBtn:removeSelf();
    print("Start Game")
end

startBtn = widget.newButton(
    {
    left = 75,
    top = 100,
    id = "startBtn",
    label = "Start",
    onEvent = start
    }
)

当我点击START按钮时,它应该带我到这里的FIRST LEVEL 并且是我遇到问题的地方。

local composer = require( "composer" );
local scene = composer.newScene();
local widget = require ("widget");

function scene:create( event )

    local sceneGroup = self.view;

end

function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase
    local params = event.params;
    print(params);

    if (phase == "will") then
        print("Will")
    elseif (phase == "did") then
        print("Did")
        local bg = display.newImage ("bg.png",  
        display.contentCenterX, display.contentCenterY);


        ------- ALEX KIDD  ---------------------------------
        local options =
        {
            frames = {
                { x = 1, y = 2, width = 16, height = 25}, --frame 1       
                { x = 18, y = 2, width = 16, height = 25}, --frame 2        
                { x = 35, y = 2, width = 16, height = 25}, --frame 3        
                { x = 52, y = 2, width = 16, height = 25}, --frame 4
                { x = 1, y = 54, width = 16, height = 24},  --ready1
                { x = 19, y = 54, width = 16, height = 24}, --ready2
                { x = 37, y = 54, width = 29, height = 24}, -- rock
                { x = 67, y = 54, width = 33, height = 24}, -- scissor
                { x = 101, y = 54, width = 33, height = 24},  -- paper       
            }
        };
        local sheet = graphics.newImageSheet( "kidd.png", options );


        -- Create animation sequence for animation
        local seqData = {
            {name = "normal", start=1 , count = 4, time = 800},
            {name = "faster", frames={1,2,3,4}, time = 400},
            {name = "shake", frames={5,6}, time = 500},
            {name = "rock", frames={7}},
            {name = "paper", frames={9}},
            {name = "scissor", frames={8}},

        }
        local alex = display.newSprite (sheet, seqData);
        alex.x = display.contentCenterX-100;
        alex.y = display.contentCenterY+83;

        alex.anchorX = 1;
        alex.anchorY = 1;



        ---------- JANKEN ---------------------------------
        local jankenOpt =
        {
            frames = {
                {x= 154, y= 13, width= 39, height= 48 }, -- shake1
                {x= 195, y= 13, width= 39, height= 48 }, -- shake2
                {x= 236, y= 13, width= 32, height= 48 }, -- set
                {x= 270, y= 13, width= 16, height= 48 }, --r/p/s
                {x= 287, y= 13, width= 16, height= 48 }, --r/p/s
                {x= 305, y= 13, width= 15, height= 48 }, --r/p/s
                {x= 69, y= 13, width= 41, height= 48 }, --flap1
                {x= 110, y= 13, width= 40, height= 48 }, --flap2
            }
        };
        local jankenSheet = graphics.newImageSheet( "chars.png", jankenOpt );

        -- Create animation sequence janken
        local seqDataJanken = {
            {name = "flap", frames={7,8}, time = 500},
            {name = "shake", frames={1,2}, time = 500},    
            {name = "set", frames={3}, time = 10, loopCount=1},        
        }

        local janken = display.newSprite (jankenSheet, seqDataJanken);

        janken.x = display.contentCenterX+100;
        janken.y = display.contentCenterY+83;

        janken.anchorX = 1;
        janken.anchorY = 1;


        -------------- button setup
        local btnOpt =
        {
            frames = {
                { x = 3, y = 2, width=70, height = 22}, --frame 1       
                { x = 78, y = 2, width=70, height = 22}, --frame 2        
            }
        };

        local buttonSheet = graphics.newImageSheet( "button.png", btnOpt );

        local function foo (wow) 
            alex:play();        
            janken:play();
        end

        local function bar (wow)
            alex:pause();    
            janken:pause();    
            --alex:setFrame(2);     --keep it at this frame 

            -- NEXT: generate more buttons
        end

        -- Function to handle button event
        local function go( event )
            -- event.target is the button widget
            print (event.phase, event.target.id)

            transition.to(alex, {time=2000, x=170, onStart = foo, onComplete = bar})
        end

        local btnGo = widget.newButton(
            {
                x = 200,
                y = 20,    
                id = "btnGo",
                label = "Go!",
                labelColor = { default={ 0, 0, 0 }, over={ 0, 0, 0 } },    
                sheet = buttonSheet,
                defaultFrame = 1,
                overFrame = 2,
                onPress = go,
            }
        );

        -------------- play buttons

        local function shoot (buttonID) 

            local randomHand = math.random(4,6);
            -- position Janken and draw his hands
            janken:setSequence("set"); 
            hand = display.newImage (jankenSheet, randomHand, display.contentCenterX+61, display.contentCenterY+60);

            if (buttonID == "btnRock") then
                alex:setSequence("rock");  -- just show rock for now
            elseif (buttonID == "btnScissor") then  
                alex:setSequence("scissor");  -- just show rock for now
            else
                alex:setSequence("paper");  -- just show rock for now
            end
        end


        local function play (event)
            if (event.phase == "ended") then
                alex:setSequence ("shake");
                alex:play();

                janken:setSequence("shake");
                janken:play(); 


                local t = timer.performWithDelay (1500, function() shoot(event.target.id) end, 1);


                print (event.target.id);   -- which button was it?
            end
        end


        local btnRock = widget.newButton(
            {
                x = 80,
                y = 20,    
                id = "btnRock",
                label = "Rock",
                labelColor = { default={ 0, 0, 0 }, over={ 0, 0, 0 } },    
                sheet = buttonSheet,
                defaultFrame = 1,
                overFrame = 2,
                onEvent = play,
            }
        );

        local btnPaper = widget.newButton(
            {
                x = 80,
                y = 50,    
                id = "btnPaper",
                label = "Paper",
                labelColor = { default={ 0, 0, 0 }, over={ 0, 0, 0 } },    
                sheet = buttonSheet,
                defaultFrame = 1,
                overFrame = 2,
                onEvent = play,
            }
        );

        local btnScissor = widget.newButton(
            {
                x = 80,
                y = 80,    
                id = "btnScissor",
                label = "Scissor",
                labelColor = { default={ 0, 0, 0 }, over={ 0, 0, 0 } },    
                sheet = buttonSheet,
                defaultFrame = 1,
                overFrame = 2,
                onEvent = play,
            }
        );

        local scoreAlex = display.newText ( {text="Alex: 0", x=230, y=60, fontSize=20});

        scoreAlex:setFillColor (0,0,0);
        scoreAlex.anchorX = 1;

    end

end

function scene:hide( event )
    local sceneGroup = self.view

    local phase = event.phase

    if ( phase == "will" ) then
        transition.cancel(enemy);
    elseif ( phase == "did" ) then

    end

end


scene:addEventListener( "create", scene )
scene:addEventListener( "enter", scene )
scene:addEventListener( "hide", scene )

return scene

1 个答案:

答案 0 :(得分:1)

嗯,您正在添加一个应该 test1@ubuntudesk:~/chef-repo$ knife bootstrap 192.168.131.111 -x test1 -P BatmanRobin -N unode --sudo Node unode exists, overwrite it? (Y/N) Y Client unode exists, overwrite it? (Y/N) Y Creating new client for unode Creating new node for unode Connecting to 192.168.131.111 192.168.131.111 knife sudo password: Enter your password: 192.168.131.111 192.168.131.111 -----> Installing Chef Omnibus (-v 12) 192.168.131.111 downloading https://omnitruck-direct.chef.io/chef/install.sh 192.168.131.111 to file /tmp/install.sh.6624/install.sh 192.168.131.111 trying wget... 192.168.131.111 ubuntu 16.04 x86_64 192.168.131.111 Getting information for chef stable 12 for ubuntu... 192.168.131.111 downloading https://omnitruck-direct.chef.io/stable/chef/metadata?v=12&p=ubuntu&pv=16.04&m=x86_64 192.168.131.111 to file /tmp/install.sh.6628/metadata.txt 192.168.131.111 trying wget... 192.168.131.111 sha1 a2de7d933734d3a0c4b859576d0be472c5cd55f7 192.168.131.111 sha256 7073541beb4294c994d4035a49afcf06ab45b3b3933b98a65b8059b7591df6b8 192.168.131.111 url https://packages.chef.io/files/stable/chef/12.15.19/ubuntu/16.04/chef_12.15.19-1_amd64.deb 192.168.131.111 version 12.15.19 192.168.131.111 downloaded metadata file looks valid... 192.168.131.111 downloading https://packages.chef.io/files/stable/chef/12.15.19/ubuntu/16.04/chef_12.15.19-1_amd64.deb 192.168.131.111 to file /tmp/install.sh.6628/chef_12.15.19-1_amd64.deb 192.168.131.111 trying wget... 192.168.131.111 Comparing checksum with sha256sum... 192.168.131.111 Installing chef 12 192.168.131.111 installing with dpkg... 192.168.131.111 Selecting previously unselected package chef. (Reading database ... 175392 files and directories currently installed.) 192.168.131.111 Preparing to unpack .../chef_12.15.19-1_amd64.deb ... 192.168.131.111 Unpacking chef (12.15.19-1) ... 192.168.131.111 Setting up chef (12.15.19-1) ... 192.168.131.111 Thank you for installing Chef! 192.168.131.111 Starting the first Chef Client run... 192.168.131.111 Starting Chef Client, version 12.15.19 192.168.131.111 [2016-10-18T15:43:22-07:00] ERROR: Error connecting to https://cent7/organizations/test1k/nodes/unode, retry 1/5 192.168.131.111 [2016-10-18T15:43:27-07:00] ERROR: Error connecting to https://cent7/organizations/test1k/nodes/unode, retry 2/5 192.168.131.111 [2016-10-18T15:43:32-07:00] ERROR: Error connecting to https://cent7/organizations/test1k/nodes/unode, retry 3/5 192.168.131.111 [2016-10-18T15:43:37-07:00] ERROR: Error connecting to https://cent7/organizations/test1k/nodes/unode, retry 4/5 192.168.131.111 [2016-10-18T15:43:42-07:00] ERROR: Error connecting to https://cent7/organizations/test1k/nodes/unode, retry 5/5 192.168.131.111 192.168.131.111 ================================================================================ 192.168.131.111 Chef encountered an error attempting to load the node data for "unode" 192.168.131.111 ================================================================================ 192.168.131.111 192.168.131.111 Networking Error: 192.168.131.111 ----------------- 192.168.131.111 Error connecting to https://cent7/organizations/test1k/nodes/unode - Failed to open TCP connection to cent7:443 (getaddrinfo: Name or service not known) 192.168.131.111 192.168.131.111 Your chef_server_url may be misconfigured, or the network could be down. 192.168.131.111 192.168.131.111 Relevant Config Settings: 192.168.131.111 ------------------------- 192.168.131.111 chef_server_url "https://cent7/organizations/test1k" 192.168.131.111 192.168.131.111 Platform: 192.168.131.111 --------- 192.168.131.111 x86_64-linux 192.168.131.111 192.168.131.111 192.168.131.111 Running handlers: 192.168.131.111 [2016-10-18T15:43:47-07:00] ERROR: Running exception handlers 192.168.131.111 Running handlers complete 192.168.131.111 [2016-10-18T15:43:47-07:00] ERROR: Exception handlers complete 192.168.131.111 Chef Client failed. 0 resources updated in 27 seconds 192.168.131.111 [2016-10-18T15:43:47-07:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out 192.168.131.111 [2016-10-18T15:43:47-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report 192.168.131.111 [2016-10-18T15:43:47-07:00] ERROR: Error connecting to https://cent7/organizations/test1k/nodes/unode - Failed to open TCP connection to cent7:443 (getaddrinfo: Name or service not known) 192.168.131.111 [2016-10-18T15:43:47-07:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) 的监听器scene:addEventListener( "enter", scene )(更改输入显示)

您的听众甚至没有被解雇,因为它没有添加正确的名称。

Composer使用以下事件:create, destroy, show, hide