Technowand,
It doesn’t work if I put the code the way you have it. I will paste the code below the way I have it and it is working fine. I really need help on the second coding that is listed though. It’s my backbutton that is not working on the gameboard page. It will not let me change the touched to match. You will see that is different.
[lua]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 physics = require (“physics”)
physics.start ()
borderBodyElement = { friction = 0.5, bounce=0.5 }
local borderBottom = display.newRect( 0, 320, 460, 20 )
borderBottom:setFillColor( 0, 0, 0, 0 )
physics.addBody( borderBottom, “static”, borderBodyElement )
local borderLeft = display.newRect( 0, 20, 20, 460 )
borderLeft:setFillColor( 0, 0, 0, 0 )
physics.addBody( borderLeft, “static”, borderBodyElement )
localGroup:insert(borderLeft)
local borderRight = display.newRect( 300, 20, 20, 460 )
borderLeft:setFillColor( 0, 0, 0, 0 )
physics.addBody( borderRight, “static”, borderBodyElement )
localGroup:insert(borderRight)
local background = display.newImage (“title2.png”)
background.x = 240
localGroup:insert(background)
–> This sets the background
local instructions = display.newImage (“instructions.png”)
instructions.x = 100
instructions.y = 240
instructions.xScale = .5
instructions.yScale = .5
localGroup:insert(instructions)
–>This places the instructions button
local function touchedInstructions (event)
if (“ended” == event.phase) then
director:changeScene (“gameboard”, “fade”)
end
end
instructions:addEventListener (“touch”, touchedInstructions)
function new()
–>MUST return a dislay.newGroup()
print(“titlescreen”)
return localGroup
end
local highscores = display.newImage (“highscores.png”)
highscores.x = 380
highscores.y = 240
highscores.xScale = .5
highscores.yScale = .5
localGroup:insert(highscores)
local startbutton = display.newImage (“startbutton.png”)
startbutton.x = 240
startbutton.y = 200
startbutton.xScale = .5
startbutton.yScale = .5
localGroup:insert(startbutton)
local greenblock = display.newImage( “greenblock.png” )
greenblock.x = 80; greenblock.y = 50; greenblock.rotation = 5
greenblock.xScale = 0; greenblock.yScale = 0
localGroup:insert(greenblock)
physics.addBody( greenblock, { density=1.0, friction=0.5, bounce= 0.4 } )
local purpleblock = display.newImage( “purpleblock.png” )
purpleblock.x = 150; purpleblock.y = 70; purpleblock.rotation = 10
purpleblock.xScale = 0; purpleblock.yScale = 0
localGroup:insert(purpleblock)
physics.addBody( purpleblock, { density=2.0, friction=0.5, bounce= 0.4 } )
local orangeblock = display.newImage( “orangeblock.png” )
orangeblock.x = 370; orangeblock.y = 60; orangeblock.rotation = 10
orangeblock.xScale = 0; orangeblock.yScale = 0
localGroup:insert(orangeblock)
physics.addBody( orangeblock, { density=4.0, friction=0.5, bounce= 0.4 } )
local yellowblock = display.newImage( “yellowblock.png” )
yellowblock.x = 400; yellowblock.y = 80; yellowblock.rotation = 10
yellowblock.xScale = 0; yellowblock.yScale = 0
localGroup:insert(yellowblock)
physics.addBody( yellowblock, { density=3.0, friction=0.5, bounce= 0.4 } )
local redblock = display.newImage( “redblock.png” )
redblock.x = 300; redblock.y = 50; redblock.rotation = 5
redblock.xScale = 0; redblock.yScale = 0
localGroup:insert(redblock)
physics.addBody( redblock, { density=2.0, friction=0.5, bounce= 0.4 } )
–This begins the redblock drag code
local redblockx0, redblocky0
local function startDrag( event )
local redblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
redblockx0 = redblock.x
redblocky0 = redblock.y
print(x0, y0)
– Stop current motion, if any
redblock:setLinearVelocity( 0, 0 )
redblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
redblock.x = redblockx0 + event.x - x0
redblock.y = redblocky0 + event.y - y0
end
–>This ends the redblock drag code
–>Stop further propagtion of touch event!
return true
end
redblock:addEventListener( “touch”, startDrag );
end[/lua]
This is the page that has the backbutton that is not working. It’s the same thing I pasted above when we first started talking. I pasted the entire page this time. It’s long because I have coding for sixteen blocks. If you know a way to place the blocks on in shorten code let me know BUT the backbutton is what is not working.
[lua]module(…, package.seeall)
–>main function - MUST return a display.newGroup()
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 physics = require (“physics”)
physics.start ()
–>Background
local background = display.newImage (“blackbackground.png”)
localGroup:insert(background)
–> This sets the background
–>Gameboard
local gameboard = display.newImage (“gameboard.png”)
gameboard.x = 310
gameboard.y = 200
localGroup:insert(gameboard)
–>This sets the gameboard
local redblock = display.newImage (“redblock.png”)
localGroup:insert(redblock)
redblock.x = 70
redblock.y = 50
local redblockx0, redblocky0
local function startDrag( event )
local redblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
redblockx0 = redblock.x
redblocky0 = redblock.y
print(x0, y0)
– Stop current motion, if any
redblock:setLinearVelocity( 0, 0 )
redblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
redblock.x = redblockx0 + event.x - x0
redblock.y = redblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
redblock:addEventListener( “touch”, startDrag );
–>This ends the redblock drag code
local redblock = display.newImage (“redblock.png”)
localGroup:insert(redblock)
redblock.x = 75
redblock.y = 50
local redblockx0, redblocky0
local function startDrag( event )
local redblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
redblockx0 = redblock.x
redblocky0 = redblock.y
print(x0, y0)
– Stop current motion, if any
redblock:setLinearVelocity( 0, 0 )
redblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
redblock.x = redblockx0 + event.x - x0
redblock.y = redblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
redblock:addEventListener( “touch”, startDrag );
–>This ends the redblock drag code
local redblock = display.newImage (“redblock.png”)
localGroup:insert(redblock)
redblock.x = 80
redblock.y = 50
local redblockx0, redblocky0
local function startDrag( event )
local redblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
redblockx0 = redblock.x
redblocky0 = redblock.y
print(x0, y0)
– Stop current motion, if any
redblock:setLinearVelocity( 0, 0 )
redblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
redblock.x = redblockx0 + event.x - x0
redblock.y = redblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
redblock:addEventListener( “touch”, startDrag );
–>This ends the redblock drag code
local redblock = display.newImage (“redblock.png”)
localGroup:insert(redblock)
redblock.x = 85
redblock.y = 50
local redblockx0, redblocky0
local function startDrag( event )
local redblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
redblockx0 = redblock.x
redblocky0 = redblock.y
print(x0, y0)
– Stop current motion, if any
redblock:setLinearVelocity( 0, 0 )
redblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
redblock.x = redblockx0 + event.x - x0
redblock.y = redblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
redblock:addEventListener( “touch”, startDrag );
–>This ends the redblock drag code
–>This begins the purpleblock image insert and drag code
local purpleblock = display.newImage (“purpleblock.png”)
localGroup:insert(purpleblock)
purpleblock.x = 190
purpleblock.y = 50
local purpleblockx0, purpleblocky0
local function startDrag( event )
local purpleblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
purpleblockx0 = purpleblock.x
purpleblocky0 = purpleblock.y
print(x0, y0)
– Stop current motion, if any
purpleblock:setLinearVelocity( 0, 0 )
purpleblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
purpleblock.x = purpleblockx0 + event.x - x0
purpleblock.y = purpleblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
purpleblock:addEventListener( “touch”, startDrag );
–>This ends the purpleblock drag code
–>This begins the purpleblock image insert and drag code
local purpleblock = display.newImage (“purpleblock.png”)
localGroup:insert(purpleblock)
purpleblock.x = 195
purpleblock.y = 50
local purpleblockx0, purpleblocky0
local function startDrag( event )
local purpleblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
purpleblockx0 = purpleblock.x
purpleblocky0 = purpleblock.y
print(x0, y0)
– Stop current motion, if any
purpleblock:setLinearVelocity( 0, 0 )
purpleblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
purpleblock.x = purpleblockx0 + event.x - x0
purpleblock.y = purpleblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
purpleblock:addEventListener( “touch”, startDrag );
–>This ends the purpleblock drag code
–>This begins the purpleblock image insert and drag code
local purpleblock = display.newImage (“purpleblock.png”)
localGroup:insert(purpleblock)
purpleblock.x = 200
purpleblock.y = 50
local purpleblockx0, purpleblocky0
local function startDrag( event )
local purpleblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
purpleblockx0 = purpleblock.x
purpleblocky0 = purpleblock.y
print(x0, y0)
– Stop current motion, if any
purpleblock:setLinearVelocity( 0, 0 )
purpleblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
purpleblock.x = purpleblockx0 + event.x - x0
purpleblock.y = purpleblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
purpleblock:addEventListener( “touch”, startDrag );
–>This ends the purpleblock drag code
–>This begins the yellowblock image insert and drag code
local yellowblock = display.newImage (“yellowblock.png”)
localGroup:insert(yellowblock)
yellowblock.x = 305
yellowblock.y = 50
local yellowblockx0, yellowblocky0
local function startDrag( event )
local yellowblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
yellowblockx0 = yellowblock.x
yellowblocky0 = yellowblock.y
print(x0, y0)
– Stop current motion, if any
yellowblock:setLinearVelocity( 0, 0 )
yellowblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
yellowblock.x = yellowblockx0 + event.x - x0
yellowblock.y = yellowblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
yellowblock:addEventListener( “touch”, startDrag );
–>This ends the yellowblock drag code
–>This begins the yellowblock image insert and drag code
local yellowblock = display.newImage (“yellowblock.png”)
localGroup:insert(yellowblock)
yellowblock.x = 310
yellowblock.y = 50
local yellowblockx0, yellowblocky0
local function startDrag( event )
local yellowblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
yellowblockx0 = yellowblock.x
yellowblocky0 = yellowblock.y
print(x0, y0)
– Stop current motion, if any
yellowblock:setLinearVelocity( 0, 0 )
yellowblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
yellowblock.x = yellowblockx0 + event.x - x0
yellowblock.y = yellowblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
yellowblock:addEventListener( “touch”, startDrag );
–>This ends the yellowblock drag code
–>This begins the yellowblock image insert and drag code
local yellowblock = display.newImage (“yellowblock.png”)
localGroup:insert(yellowblock)
yellowblock.x = 315
yellowblock.y = 50
local yellowblockx0, yellowblocky0
local function startDrag( event )
local yellowblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
yellowblockx0 = yellowblock.x
yellowblocky0 = yellowblock.y
print(x0, y0)
– Stop current motion, if any
yellowblock:setLinearVelocity( 0, 0 )
yellowblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
yellowblock.x = yellowblockx0 + event.x - x0
yellowblock.y = yellowblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
yellowblock:addEventListener( “touch”, startDrag );
–>This ends the yellowblock drag code
–>This begins the orangeblock image insert and drag code
local orangeblock = display.newImage (“orangeblock.png”)
localGroup:insert(orangeblock)
orangeblock.x = 75
orangeblock.y = 140
local orangeblockx0, orangeblocky0
local function startDrag( event )
local orangeblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
orangeblockx0 = orangeblock.x
orangeblocky0 = orangeblock.y
print(x0, y0)
– Stop current motion, if any
orangeblock:setLinearVelocity( 0, 0 )
orangeblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
orangeblock.x = orangeblockx0 + event.x - x0
orangeblock.y = orangeblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
orangeblock:addEventListener( “touch”, startDrag );
–>This ends the orangeblock drag code
–>This begins the orangeblock image insert and drag code
local orangeblock = display.newImage (“orangeblock.png”)
localGroup:insert(orangeblock)
orangeblock.x = 80
orangeblock.y = 140
local orangeblockx0, orangeblocky0
local function startDrag( event )
local orangeblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
orangeblockx0 = orangeblock.x
orangeblocky0 = orangeblock.y
print(x0, y0)
– Stop current motion, if any
orangeblock:setLinearVelocity( 0, 0 )
orangeblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
orangeblock.x = orangeblockx0 + event.x - x0
orangeblock.y = orangeblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
orangeblock:addEventListener( “touch”, startDrag );
–>This ends the orangeblock drag code
–>This begins the orangeblock image insert and drag code
local orangeblock = display.newImage (“orangeblock.png”)
localGroup:insert(orangeblock)
orangeblock.x = 85
orangeblock.y = 140
local orangeblockx0, orangeblocky0
local function startDrag( event )
local orangeblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
orangeblockx0 = orangeblock.x
orangeblocky0 = orangeblock.y
print(x0, y0)
– Stop current motion, if any
orangeblock:setLinearVelocity( 0, 0 )
orangeblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
orangeblock.x = orangeblockx0 + event.x - x0
orangeblock.y = orangeblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
orangeblock:addEventListener( “touch”, startDrag );
–>This ends the orangeblock drag code
–>This begins the greenblock image insert and drag code
local greenblock = display.newImage (“greenblock.png”)
localGroup:insert(greenblock)
greenblock.x = 75
greenblock.y = 230
local greenblockx0, greenblocky0
local function startDrag( event )
local greenblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
greenblockx0 = greenblock.x
greenblocky0 = greenblock.y
print(x0, y0)
– Stop current motion, if any
greenblock:setLinearVelocity( 0, 0 )
greenblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
greenblock.x = greenblockx0 + event.x - x0
greenblock.y = greenblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
greenblock:addEventListener( “touch”, startDrag );
–>This ends the greenblock drag code
–>This begins the greenblock image insert and drag code
local greenblock = display.newImage (“greenblock.png”)
localGroup:insert(greenblock)
greenblock.x = 80
greenblock.y = 230
local greenblockx0, greenblocky0
local function startDrag( event )
local greenblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
greenblockx0 = greenblock.x
greenblocky0 = greenblock.y
print(x0, y0)
– Stop current motion, if any
greenblock:setLinearVelocity( 0, 0 )
greenblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
greenblock.x = greenblockx0 + event.x - x0
greenblock.y = greenblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
greenblock:addEventListener( “touch”, startDrag );
–>This ends the greenblock drag code
–>This begins the greenblock image insert and drag code
local greenblock = display.newImage (“greenblock.png”)
localGroup:insert(greenblock)
greenblock.x = 85
greenblock.y = 230
local greenblockx0, greenblocky0
local function startDrag( event )
local greenblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
greenblockx0 = greenblock.x
greenblocky0 = greenblock.y
print(x0, y0)
– Stop current motion, if any
greenblock:setLinearVelocity( 0, 0 )
greenblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
greenblock.x = greenblockx0 + event.x - x0
greenblock.y = greenblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
greenblock:addEventListener( “touch”, startDrag );
–>This ends the greenblock drag code
local backbutton = display.newImage (“backbutton.png”)
localGroup:insert(backbutton)
backbutton.x = 75
backbutton.y = 300
backbutton.xScale = .5
backbutton.yScale = .5
local function touched (event)
if (“ended” == event.phase) then
director:changeScene( “titlescreen”, “fade” )
end
end
backbutton:addEventListener (“touch”, touch)
–>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: 72372 topic_id: 12420 reply_id: 45838[/import]