Transition issues

Hey Everybody,

I am a newby working on my first game. I am using the director file to transition to other screens. I have the screen where it will transition when I click on a button but when it goes to the screen my other images on that screen will not show up. The only thing that shows up is my background. Please see my code for my second screen below.
module(…, package.seeall)

function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file


local background = display.newImage (“blackbackground.png”)
localGroup:insert(background)
–> This sets the background

local gameboard = display.newimage (“gameboard.png”)
gameboard.x = 100
gameboard.y = 240
localGroup:insert(gameboard)
–> This places our gameboard

local backbutton = display.newImage (“backbutton.png”)
backbutton.x = 100
backbutton.y = 240
localGroup:insert(backbutton)
–> This places our “back” button

local function pressBack (event)
if event.phase == “ended” then
director:changeScene (“titlescreen”)
end
end

backbutton:addEventListener (“touch”, pressBack)
–> This adds the function and listener to the “back” button



return localGroup
end
–> This is how we end every file except for director and main, as mentioned in my first comment [import]uid: 72372 topic_id: 12141 reply_id: 312141[/import]

Please put your code in lua tags as it makes it infinitely easier to read and much more likely that you will be helped.

I do see a problem with this line.
[lua]local gameboard = display.newimage(“gameboard.png”)[/lua]
Don’t forget to not only check spelling but upper and lowering casing as well. [import]uid: 27965 topic_id: 12141 reply_id: 44173[/import]

Thanks I I overlooked that. I’m a newby so what do you mean by putting my code in lua tags? How do I do that? [import]uid: 72372 topic_id: 12141 reply_id: 44175[/import]

Hey, caleb you sound like me :wink:

Do, without any spaces, < lua > before your code and < / lua > after it.

If you can post your title screen code and also the code for the screen you are transitioning to, maybe we can help :slight_smile:

Peach

PS - Are you displaying your background image after your other images in this other lua file by any chance? [import]uid: 52491 topic_id: 12141 reply_id: 44194[/import]

I got the earlier problem figured out and thank you everybody. I’m confused about calling out the Lua Code. Do you want me to call out every line below with those tags? I’m sorry I know this is simple but I don’t understand. Everything is code I thought except when I put notes for myself which is designated with a -->

Anyway the issue I have now is that I push the instructions button and it takes me to the Instructions screen. On that screen I am showing my background, the gameboard, and the back button. I’m having problems with the back button working to get me back to my previous screen. When I press it, nothing happens and it stays on this screen

title screen code (Down to the Instructions button that I want pushed)
module(…, package.seeall)

function new()
local Group = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
–> and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file


local physics = require(“physics”)
physics.start()

borderBodyElement = { friction = 0.5, bounce=0.3 }

local borderLeft = display.newRect( 0, 20, 20, 460 )
borderLeft:setFillColor( 0, 0, 0, 0 )
physics.addBody( borderLeft, “static”, borderBodyElement )

local borderRight = display.newRect( 300, 20, 20, 460 )
borderLeft:setFillColor( 0, 0, 0, 0 )
physics.addBody( borderRight, “static”, borderBodyElement )

local background = display.newImage (“title2.png”)
background.x = 240
–> This sets the background

local instructions = display.newImage (“instructions.png”)
instructions.x = 100
instructions.y = 240
instructions.xScale = .5
instructions.yScale = .5

–>This places the instructions button

local function pressInstructions (event)
if event.phase == “ended” then
director:changeScene (“gameboard”)
end
end

instructions:addEventListener (“touch”, pressInstructions)

***********************
This is the code for the Instructions Screen that it transitions too.
module(…, package.seeall)

local localGroup

–>main function - MUST return a display.newGroup()
function new()
localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
–> and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file


–Bacground
local background = display.newImage (“blackbackground.png”)
localGroup:insert(background)
–> This sets the background

local backbutton = display.newImage (“backbutton.png”)
localGroup:insert(backbutton)
backbutton.x = 75
backbutton.y = 300
backbutton.xScale = .5
backbutton.yScale = .5

local gameboard = display.newImage (“gameboard.png”)
gameboard.x = 310
gameboard.y = 200
localGroup:insert(gameboard)

local function touched (event)
if event.phase == “ended” then
director:changeScene(“titlescreen”, “fade”)

end
end

backbutton:addEventListener (“touch”, press)
–>MUST return a display.newGroup()



return localGroup
end
–> This is how we end every file except for director and main, as mentioned in my first comment [import]uid: 72372 topic_id: 12141 reply_id: 44217[/import]

Peach, I’ve noticed you have expanded upon some of my posts (which are often written when I’m not fully awake) and I really appreciate it, Thank You!

Tags are really easy once you know how to use them. You don’t have to use tags on every line of code just put this tag [text][lua][/text] before it and this tag [text][/lua][/text] at the end. So when you post, what you will see is this:
[text][lua][/text]
local thatsCool = display.newImage(“yay.png”)
[text][lua][/text]
and anyone reading your post will see this:
[lua]local thatsCool = display.newImage(“yay.png”)[/lua]Hope that clears up tags for you.

It looks like the problem is that the function the backbutton eventListener is calling has a different name than the function you have declared above it. The eventListener is trying to call a function called “press” while the function you have declared is called “touched” so either change the name of the function or the function name in the eventListener. [import]uid: 27965 topic_id: 12141 reply_id: 44265[/import]

Calebr2048,

The button works on my titlescreen and I use the same logic on the Instructions screen where it doesn’t work. When I press the Instructions button on the titlescreen, it goes to the next page instructions screen) but when I press the Back button on that screen nothing happens. Do you see something different in the two pages? I copied the logic from one page to the next page. [import]uid: 72372 topic_id: 12141 reply_id: 44278[/import]

I have added comments to your code to show you what I’m talking about.
[lua]–***********************
–This is the code for the Instructions Screen that it transitions too.

module(…, package.seeall)

local localGroup

–>main function - MUST return a display.newGroup()
function new()
localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
–> and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file


–Bacground
local background = display.newImage (“blackbackground.png”)
localGroup:insert(background)
–> This sets the background

local backbutton = display.newImage (“backbutton.png”)
localGroup:insert(backbutton)
backbutton.x = 75
backbutton.y = 300
backbutton.xScale = .5
backbutton.yScale = .5

local gameboard = display.newImage (“gameboard.png”)
gameboard.x = 310
gameboard.y = 200
localGroup:insert(gameboard)
– NEW COMMENT BELOW –
– this function is never called which means the titlescreen is never loaded
local function touched (event)
if event.phase == “ended” then
director:changeScene(“titlescreen”, “fade”)

end
end
– NEW COMMENT BELOW –
– the backbutton is trying to call a function called press which isn’t in your code
backbutton:addEventListener (“touch”, press)
– NEW COMMENT BELOW –
– either change press to touched or change the name of the function above
– from touched to press

–>MUST return a display.newGroup()



return localGroup
end
–> This is how we end every file except for director and main, as mentioned in my first comment[/lua] [import]uid: 27965 topic_id: 12141 reply_id: 44287[/import]

Okay,

I tried changing the words to match by first changing them to say press and then I tried touched. Both times when I relaunced it would not transition to the screen it just relaunced the first screen again so I couldn’t even get to the second screen when I pressed Instructions. And when it relaunced it was delayed when I pushed the button like it didn’t know I pushed the button but it did relaunce the first screen. [import]uid: 72372 topic_id: 12141 reply_id: 44326[/import]

Thanks Caleb; your posts are great and always well written, sometimes I can just foresee the OP wanting further clarification, or others finding the thread with similar questions - so I try to jump in :wink:

Thanks too for the post on tags; it’s better than I’d have explained it - as you likely know as we’re in many of the same threads.

Now - if the problem is in your instructions screen you need to reexamine your logic there; there WILL be some error, you just have to hunt it down.

Peach :slight_smile: [import]uid: 52491 topic_id: 12141 reply_id: 44374[/import]