ok, so I made some modifications, bu still cant get collision detection to work (I left “print” in so I can see the results in terminal). Do I need to end the drag listeners so the collision listeners will work? Should I use gameUI instead? Sorry, I am new to this and still learning. Thanks again!
[code]
module(…, package.seeall)
local imagelookup = require("_imagelookup")
local animlookup = require("_animlookup")
local physics = require(“physics”)
physics.start()
function newlevel1 ()
local this = display.newGroup()
local background = display.newImageRect(imagelookup.table[“Sunshine”],imagelookup.table[“SunshineWidth”],imagelookup.table[“SunshineHeight”])
background.x, background.y = 384, 512
background.xScale = 0.45714285714285713
background.yScale = 0.9752380952380952
background.isVisible = true
physics.addBody(background, “kinematic”, {density = 1.0, friction = 0.3, bounce = 0.2})
this:insert(background)
this.background = background
local firstblock_1 = display.newImageRect(imagelookup.table[“Firstblock”],imagelookup.table[“FirstblockWidth”],imagelookup.table[“FirstblockHeight”])
firstblock_1.x, firstblock_1.y = 192, 700
firstblock_1.xScale = 1
firstblock_1.yScale = 1
firstblock_1.isVisible = true
physics.addBody(firstblock_1, “kinematic”, {density = 1.0, friction = 0.3, bounce = 0.2})
this:insert(firstblock_1)
this.firstblock_1 = firstblock_1
local nextblock_1 = display.newImage(imagelookup.table[“Nextblock”],imagelookup.table[“NextblockWidth”],imagelookup.table[“NextblockHeight”])
nextblock_1.x, nextblock_1.y = 384, 700
nextblock_1.xScale = 1
nextblock_1.yScale = 1
nextblock_1.isVisible = true
nextblock_1.objectName = “nextblock_1”
physics.addBody(nextblock_1, “kinematic”, {density = 1.0, friction = 0.3, bounce = 0.2})
this:insert(nextblock_1)
this.nextblock_1 = nextblock_1
local lastblock_1 = display.newImage(imagelookup.table[“Lastblock”],imagelookup.table[“LastblockWidth”],imagelookup.table[“LastblockHeight”])
lastblock_1.x, lastblock_1.y = 576, 700
lastblock_1.xScale = 1
lastblock_1.yScale = 1
lastblock_1.isVisible = true
physics.addBody(lastblock_1, “kinematic”, {density = 1.0, friction = 0.3, bounce = 0.2})
this:insert(lastblock_1)
this.lastblock_1 = lastblock_1
local dogbath_1 = display.newImage(imagelookup.table[“Dogbath”],imagelookup.table[“DogbathWidth”],imagelookup.table[“DogbathHeight”])
dogbath_1.x, dogbath_1.y = 192, 100
dogbath_1.xScale = 0.42857142857142855
dogbath_1.yScale = 0.42857142857142855
dogbath_1.isVisible = true
dogbath_1.objectName = “dogbath_1”
physics.addBody(dogbath_1, “kinematic”, {density = 10.0, friction = 1.0, bounce = 0.2})
this:insert(dogbath_1)
this.dogbath_1 = dogbath_1
local function movedogbath_1( event )
dogbath_1.x = event.x
dogbath_1.y = event.y
end
dogbath_1:addEventListener(“touch”, movedogbath_1)
local dirtydog0_1 = display.newImage(imagelookup.table[“Dirtydog0”],imagelookup.table[“Dirtydog0Width”],imagelookup.table[“Dirtydog0Height”])
dirtydog0_1.x, dirtydog0_1.y = 384, 100
dirtydog0_1.xScale = 0.5769230769230769
dirtydog0_1.yScale = 0.5
dirtydog0_1.isVisible = true
physics.addBody(dirtydog0_1, “kinematic”, {density = 1.0, friction = 0.3, bounce = 0.2})
this:insert(dirtydog0_1)
this.dirtydog0_1 = dirtydog0_1
local function movedirtydog0_1( event )
dirtydog0_1.x = event.x
dirtydog0_1.y = event.y
end
dirtydog0_1:addEventListener(“touch”, movedirtydog0_1)
local cleandog_1 = display.newImage(imagelookup.table[“Cleandog”],imagelookup.table[“CleandogWidth”],imagelookup.table[“CleandogHeight”])
cleandog_1.x, cleandog_1.y = 576, 100
cleandog_1.xScale = 0.3
cleandog_1.yScale = 0.45045045045045046
cleandog_1.isVisible = true
physics.addBody(cleandog_1, “kinematic”, {density = 1.0, friction = 0.3, bounce = 0.2})
this:insert(cleandog_1)
this.cleandog_1 = cleandog_1
function movecleandog_1( event )
cleandog_1.x = event.x
cleandog_1.y = event.y
end
cleandog_1:addEventListener(“touch”, movecleandog_1)
–collision detection
local function onLocalCollision( self, event )
if ( event.phase == “began” ) then
print( self.objectName … ": collision began with " … event.other.objectName )
elseif( event.phase == “ended” ) then
print( self.objectName … “: collision ended with” … event.other.objectName )
end
end
dogbath_1.collision = onLocalCollision
dogbath_1:addEventListener ( “collision”, dogbath_1 )
nextblock_1.collision = onLocalCollision
nextblock_1:addEventListener ( “collision”, nextblock_1 )
local ui = require(“ui”)
local nextbutton = ui.newButton{
defaultSrc = imagelookup.table[“Go”], defaultX = imagelookup.table[“GoWidth”], defaultY = imagelookup.table[“GoHeight”],
}
nextbutton.x, nextbutton.y = 384, 925
nextbutton.isVisible = true
physics.addBody(nextbutton, “static”, {density = 1.0, friction = 0.3, bounce = 0.2})
this:insert(nextbutton)
this.nextbutton = nextbutton
return this
end
[import]uid: 32253 topic_id: 7374 reply_id: 26283[/import]