Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Newbie problems :( — Gideros Forum

Newbie problems :(

tytadastytadas Member
edited August 2016 in General questions
I have started coding with Gideros, but now the main problem occurs.. I'm trying to move from scene1 which is the main scene with play button to scene2 where you have to select levels.. I tried to implement code by myself, but what I have done so far none of my codes worked.. :( I know, I'm a bit lazy and I could handle this by myself, but to have better future I'm asking 2 questions:

1. What's wrong with my code?
2. What's the most easiest code to move from scene1 to scene2?

local i = require("i")

local function gobutton2(i)
storyboard.gotoScene( "yellow" )
end

local btme = ui.newButton{ default="button1.png", over="button2.png", onRelease=gobutton2 }
btme.x = display.contentWidth / 2
btme.y = display.contentHeight / 2

Comments

  • n1cken1cke Maintainer
    edited August 2016 Accepted Answer
    -- here we create scenes and populate them with objects
    local scene1 = Sprite.new() -- empty scene1
    local button1 = Pixel.new(0xFF0000, 1, 100, 200) -- create first button with your GUI class
    scene1:addChild(button1) -- to add your button1 to scene1
    -- you can add more stuff you need for scene1 with `addChild`
    local scene2 = Sprite.new() -- empty scene2
    local button2 = Pixel.new(0xFF00FF, 1, 250, 100) -- create second button with your GUI class
    scene2:addChild(button2) -- to add your button2 to scene2
    --  you can add more stuff you need for scene2 with `addChild`
     
    -- event listeners for buttons
    button1:addEventListener(Event.MOUSE_DOWN, function(e)
    	if button1:hitTestPoint(e.x, e.y) then
    		stage:removeChild(scene1) -- remove scene1 from the stage
    		stage:addChild(scene2) -- add scene2 to the stage
    	end
    end)
    button2:addEventListener(Event.MOUSE_DOWN, function(e)
    	if button2:hitTestPoint(e.x, e.y) then
    		stage:removeChild(scene2) -- remove scene2 from the stage
    		stage:addChild(scene1) -- add scene1 to the stage
    	end
    end)
     
    -- display scene1
    stage:addChild(scene1)
  • tytadastytadas Member
    edited August 2016
    This definitely worked :D

    Likes: simwhi, antix

    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.