Related
I created a new project in CoronaLabs Studio with Physics-Based Game starting options and everything loaded up as a beginner I don't get where should I put addEventListener() so I can make the box to be clickable or to be destroyed on click?
I tried a bunch of different ways to just place this line of code inside the script to make the box clickable virus:applyLinearImpulse( 0, -0.25, virus.x, virus.y )
Here is the level1.lua script.
In this case, I have
require("toast")
local composer = require( "composer" )
local scene = composer.newScene()
-- include Corona's "physics" library
local physics = require("physics")
--------------------------------------------
tapCount = 0
tapText = display.newText( tapCount, display.contentCenterX, 20, native.systemFont, 40 )
--------------------------------------------
local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX
function scene:create( event )
-- Called when the scene's view does not exist.
-- INSERT code here to initialize the scene e.g. add display objects to 'sceneGroup', add touch listeners, etc.
local sceneGroup = self.view
physics.start()
physics.pause()
local background = display.newImageRect("game-background.png", 1170, 658)
background.x = display.contentCenterX
background.y = display.contentCenterY
-- OFFSCREEN BOX, position it, and rotate slightly
local box = display.newImageRect( "box.png", 40, 40 )
box.x, box.y = 160, -100
box.rotation = 33
-- add physics
physics.addBody( box, { density=1.0, friction=0.3, bounce=0.2 } )
-- create a grass object and add physics (with custom shape)
local grass = display.newImageRect( "grass.png", screenW, 82 )
grass.anchorX = 0
grass.anchorY = 1
-- draw the grass at the very bottom of the screen
grass.x, grass.y = display.screenOriginX, display.actualContentHeight + display.screenOriginY
local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 }
physics.addBody( grass, "static", { friction=0.3, shape=grassShape } )
sceneGroup:insert( background )
sceneGroup:insert( grass )
sceneGroup:insert( box )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off-screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on-screen
physics.start()
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on-screen and is about to move off-screen
physics.stop()
elseif phase == "did" then
-- Called when the scene is now off-screen
end
end
function scene:destroy( event )
-- Called prior to the removal of scene's "view" (sceneGroup)
local sceneGroup = self.view
package.loaded[physics] = nil
physics = nil
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-----------------------------------------------------------------------------------------
return scene
If I have understood your question correctly,here's an example where you can click a box and destroy it.
function scene:create(event)
local function destroyMe(event)
display.remove(event.target)
event.target=nil
end
local box = display.newImageRect( "box.png", 40, 40 )
box.x, box.y = 160, 100
box.rotation = 33
-- add physics
physics.addBody( box, { density=1.0, friction=0.3, bounce=0.2 } )
box:addEventListener("tap",destroyMe)
end
If you're using touch event,then that event will have three phases.Hence be cautious.
In my grid-based game, The player clicks on a unit then he moves his finger to determine where this unit should move. I'm using the "Jumper" library for the pathfinding. The code for getting the path works perfectly, but the code for highlighting the path, not so much.
local function onTileTouch( event )
local phase = event.phase
local tile = event.target
if ( phase == "began" ) then
-- I could create the line here
elseif ( phase == "moved" ) then
createPath( tile )
-- Getting the position of the first tile based on where the unit is
local t = tiles[currentSelectedUnit.pos.y][currentSelectedUnit.pos.x]
-- Create the line at the first tile's position
line = display.newLine( t.x, t.y, t.x, t.y )
line:setStrokeColor( 1,0,0 )
line.strokeWidth = 8
-- "foundPath" is a table of tiles of the correct path
for i=1,#foundPath do
line:append( foundPath[i].x,foundPath[i].y )
end
elseif ( phase == "ended" or phase == "cancelled" ) then
end
The line doesn't look right when being created in the "moved" phase. It does, however, look very accurate when being created in the "began" phase and then getting appended during the "moved" phase. But in this case, another extra line gets drawn that doesn't follow the path but gets directly from the start tile to the end tile.
My second problem with the "began" phase method, is I don't know how to keep deleting the old line and create a new one with for the new correct path.
Let me know if any extra information is needed.
I'm not sure what exactly you want so I have prepared my own version:
test.lua
local composer = require( 'composer' )
-- Library setup
local Grid = require ( 'jumper.grid' ) -- The grid class
local Pathfinder = require ( 'jumper.pathfinder' ) -- The pathfinder lass
local scene = composer.newScene()
-- First, set a collision map and value for walkable tiles
local board = {
tiles = {},
walkable = 0,
map = {
{0,1,0,0,0},
{0,1,0,1,0},
{0,1,0,0,0},
{0,0,0,0,0},
}
}
local function createPath( startx, starty, endx, endy )
-- Creates a grid object
local grid = Grid( board.map )
-- Creates a pathfinder object using Jump Point Search
local myFinder = Pathfinder( grid, 'JPS', board.walkable )
-- Calculates the path, and its length
local path = myFinder:getPath( startx, starty, endx, endy )
return path
end
function scene:create( event )
local sceneGroup = self.view
local rowNum = #board.map
local colNum = #board.map[1]
local width = 40
local height = width
local margin = 5
local function touch( self, event )
local phase = event.phase
local endTile = event.target
if ( phase == 'began' ) then
board.startTile = endTile
elseif ( phase == 'moved' ) then
if board.startTile ~= endTile then
if ( board.endTile ~= endTile ) then
board.endTile = endTile
local path = createPath( board.startTile.col, board.startTile.row, board.endTile.col, board.endTile.row )
if path then
-- Remove old lines
display.remove( board.lines )
board.lines = nil
-- Create new line
board.lines = display.newLine( sceneGroup, board.startTile.x, board.startTile.y, board.startTile.x, board.startTile.y + 1 )
for node, count in path:nodes() do
local id = colNum * ( node:getY() - 1 ) + node:getX()
local tile = board.tiles[id]
board.lines:append( tile.x, tile.y )
end
end
end
else
-- Remove old lines
display.remove( board.lines )
board.lines = nil
board.endTile = nil
end
elseif ( phase == 'ended' or phase == 'cancelled' ) then
-- Remove old lines
display.remove( board.lines )
board.lines = nil
board.endTile = nil
board.startTile = nil
end
end
for i=1, rowNum do
for j=1, colNum do
local tile = display.newRect( sceneGroup, (width + margin ) * j, ( height + margin ) * i, width, height )
tile.col = j
tile.row = i
tile.touch = touch
-- Add listener and change color for walkable tile
if board.map[i][j] == board.walkable then
tile:addEventListener( 'touch' )
tile:setFillColor( 0, 0.5, 0.5 )
end
local id = colNum * ( i -1 ) + j
board.tiles[id] = tile
end
end
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == 'will' then
elseif phase == 'did' then
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == 'will' then
elseif phase == 'did' then
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( 'create', scene )
scene:addEventListener( 'show', scene )
scene:addEventListener( 'hide', scene )
scene:addEventListener( 'destroy', scene )
return scene
The output I should get are the chick can jump right when i tap right and vice versa. But the two problems that I can't solve here are when I tap it will output in console like I tap twice. The second problem is the lanes are in array and keep on overlap everything, even the chick which is the player.
For this i include 2 lua files and 3 png.
This is my main.lua
display.setStatusBar( display.HiddenStatusBar )
local composer = require( "composer" )
print("entering gotoScene")
composer.gotoScene( "game2" )
print("out from gotoScene")
This is my game2.lua
---REQUIRES
local composer = require( "composer" )
local scene = composer.newScene()
local widget = require( "widget" )
local physics = require "physics"
physics.start()
physics.setGravity(0,0)
local lanes = {}
local laneID = 1
scroll = 2
---SIZE PHONE DECLARATION
local screenW = display.contentWidth --640
local screenH = display.contentHeight --1136
local halfX = display.contentWidth * 0.5 --half width 320
local halfY = display.contentHeight * 0.5 --half height 568
----------------------
----------------------
---WHEN TAP CHICK MOVE
local function tapListener( event )
local object = event.target
if object.name == "Right Side" then
print( object.name.." TAPPED!" )
if laneID < 3 then
laneID = laneID + 1;
transition.to(chick, {x=lanes[laneID].x,time=50})
print( "At lane "..laneID.." to the right")
end
return true
end
if object.name == "Left Side" then
print( object.name.." TAPPED!" )
if laneID > 1 then
laneID = laneID - 1;
transition.to(chick, {x=lanes[laneID].x,time=50})
print( "At lane "..laneID.." to the left")
end
return true
end
end
----------------------
---CREATE
-- Initialize the scene here.
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
function scene:create( )
local group = self.view
---TAP BACKGROUND
RightSide = display.newRect(500,halfY, halfX+50, screenH + 100 )
RightSide.alpha = 0.1
RightSide.name = "Right Side"
LeftSide = display.newRect(140, halfY,halfX+50, screenH + 100)
LeftSide.alpha = 0.1
LeftSide.name = "Left Side"
----------------------
---TAP LABEL
rightLabel = display.newText({ text = "", x = 0, y = 0 , fontSize = 50 } )
rightLabel:setTextColor( 0 ) ; rightLabel.x = 500 ;rightLabel.y = halfY
leftLabel = display.newText({ text = "", x = 0, y = 0, fontSize = 50 } )
leftLabel:setTextColor( 0 ) ; leftLabel.x = 150 ; leftLabel.y = halfY
----------------------
---PATHWAY (BACKGROUND)
path1 = display.newImageRect("road.png",screenW,screenH)
path1.x = halfX
path1.y = halfY
path2 = display.newImageRect("road.png",screenW,screenH)
path2.x = halfX
path2.y = halfY - screenH
----------------------
---LANES
for i=1,3 do -- loop 3 times to create 3 lanes for our game
--myGroup=display.newGroup()
laneimg = display.newImageRect("lanesroad.png", 150, 1300)
lanes[i] = laneimg
lanes[i].x = (display.contentCenterX - 140*2) + (i*140)
lanes[i].y = display.contentCenterY
lanes[i].id = i
end
----------------------
---CHICK
chick = display.newImageRect("chick.png",100,100)
chick.anchorY = 1
chick.x = lanes[2].x
chick.y = 1000
physics.addBody(chick)
chick.bodyType = "dynamic"
----------------------
path1:toBack();
path2:toBack();
group:insert( RightSide )
group:insert( LeftSide )
group:insert( rightLabel )
group:insert( leftLabel )
group:insert( laneimg)
group:insert( chick )
end
----------------------
---BACKGROUND SCROLL
function pathScroll (self,event)
path1.y = path1.y + scroll
path2.y = path2.y + scroll
if path1.y == screenH * 1.5 then
path1.y = screenH * -.5
end
if path2.y == screenH * 1.5 then
path2.y = screenH * -.5
end
end
----------------------
---SHOW --that will show in scene
function scene:show (event)
---FOR ROAD TO SCROLL
path1.enterFrame = pathScroll
Runtime:addEventListener("enterFrame", pathScroll)
path2.enterFrame = pathScroll
Runtime:addEventListener("enterFrame", pathScroll)
----------------------
---WHEN TAP TO RIGHT
RightSide:addEventListener( "tap", tapListener )
rightLabel.text = "right"
----------------------
---WHEN TAP TO LEFT
LeftSide:addEventListener( "tap", tapListener )
leftLabel.text = "left"
----------------------
end
----------------------
---HIDE
function scene:hide (event)
end
----------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
return scene
enter image description here
enter image description here
The method scene:show is called twice. Once with event.phase paramater equal to will and second time with event.phase paramater equal to did. It also apply to scene.hide method. Code below check that.
At botom I put scene template from Corona documentation. It can be used as start point for new scene.
I commented out line with Runtime:addEventListener("enterFrame", pathScroll). You have two but one is enough.
More information you find with these links
Composer Library
Introducing the Composer API
Tap / Touch / Multitouch
Try (tested)
...
---SHOW --that will show in scene
function scene:show (event)
local phase = event.phase
if ( phase == 'will' ) then
elseif ( phase == 'did' ) then
---FOR ROAD TO SCROLL
path1.enterFrame = pathScroll
Runtime:addEventListener("enterFrame", pathScroll)
path2.enterFrame = pathScroll
--Runtime:addEventListener("enterFrame", pathScroll)
----------------------
---WHEN TAP TO RIGHT
RightSide:addEventListener( "tap", tapListener )
rightLabel.text = "right"
----------------------
---WHEN TAP TO LEFT
--LeftSide:addEventListener( "tap", tapListener )
leftLabel.text = "left"
----------------------
end
end
----------------------
...
Scene template
local composer = require( "composer" )
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
end
-- show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
-- hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
end
end
-- destroy()
function scene:destroy( event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene
I'm very new to corona. I learned all from the web and this is what i produced. The game seems fine but when game over screen is displayed, the button i put to back to menu scene doesn't work and the score that player get failed to be displayed to..
Here is my code...someone kindly please help me out.. what code should i change or add to it??
Thank you. Any help is much appreciated.
local composer = require( "composer" )
local scene = composer.newScene()
local physics = require("physics")
local widget = require "widget"
physics.start()
rand = math.random( 20 )
local slap_sound = audio.loadSound("Sound/slap2.mp3")
local ow = audio.loadSound("Sound/ow.mp3")
local buttonSound = audio.loadSound("Sound/sound2.mp3")
local background
local back
local count={total1=0,total=0,touch=0,life=3}
local total
local time_remain = 5
local mossie
local bee
local shade
local gameOverScreen
local winScreen
local countdown
local life
local pauseBtn
local resumeBtn
local gametmr
---------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE
-- unless "composer.removeScene()" is called.
---------------------------------------------------------------------------------
local gameOver = function()
composer.removeScene("easy")
physics.pause()
--audio.play(gameOverSound)
background = display.newImageRect( "Images/bg.jpg", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
gameOverScreen = display.newImage("Images/gameover.png",400,300)
gameOverScreen.x = 160
gameOverScreen.y = 240
gameOverScreen.alpha = 0
transition.to(gameOverScreen,{time=500,alpha=1})
--total.isVisible = true
total.text="Score : "..count.touch
total.x = 160
total.y = 400
--total:setTextColor(000000)
botwall.isVisible = false
mossie.isVisible = false
bee.isVisible = false
life.isVisible = false
countdown.isVisible = false
pauseBtn.isVisible = false
resumeBtn.isVisible = false
local myButton = widget.newButton
{
left = 100,
top = 100,
id = "myButton",
label = "Menu",
onEvent = handleButtonEvent
}
myButton.isVisible = true
end
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
composer.gotoScene ("menu")
end
end
local function countDown(e)
time_remain = time_remain-1
countdown.text = time_remain
if time_remain == 0 then
gameOver()
end
end
local pauseGame = function(e)
if(e.phase=="ended") then
audio.play(buttonSound)
physics.pause()
timer.pause(gametmr)
pauseBtn.isVisible = false
resumeBtn.isVisible = true
return true
end
end
local resumeGame = function(e)
if(e.phase=="ended") then
audio.play(buttonSound)
physics.start()
timer.resume(gametmr)
pauseBtn.isVisible = true
resumeBtn.isVisible = false
return true
end
end
local collisionListener=function(self,event)
if(event.phase=="began")then
if(event.other.type=="mossie")then
audio.play(ow)
count.life=count.life-1
if(count.life==0) then
gameOver()
end
event.other:removeSelf()
event.other=nil
else
event.other:removeSelf()
event.other=nil
end
end
end
function onTouch(mossie)
audio.play(slap_sound)
count.touch=count.touch+1
total.text="Score : "..count.touch
mossie.target:removeSelf()
end
function killIt(e)
if(e.phase == "ended") then
gameOver()
end
end
local bottomWall = function()
botwall=display.newImage("Images/tangan.png")
botwall.x = 160
botwall.y = 500
botwall:setFillColor(22,125,185,255)
botwall.type="botwall"
botwall.collision=collisionListener
physics.addBody(botwall,"static",{ density=100.0, friction=0.0, bounce=0.0} )
botwall:addEventListener("collision",botwall)
end
local function newMossie(event)
total.text="Score : "..count.touch
life.text="Life : "..count.life
mossie = display.newImage("Images/biasa.png")
mossie.x = 60 + math.random( 160 )
mossie.y = -100
mossie.type="mossie"
mossie:setFillColor(255,0,0)
physics.addBody( mossie, { density=0.3, friction=0.2, bounce=0.5} )
mossie.name = "mossie"
mossie:addEventListener("touch",onTouch)
end
local function newBee(event)
bee = display.newImage("Images/lebah.png")
bee.x = 60 + math.random( 160 )
bee.y = -100
bee.type="other"
physics.addBody( bee, { density=1.4, friction=0.3, bounce=0.2} )
bee:addEventListener("touch",killIt)
end
-- local forward references should go here
---------------------------------------------------------------------------------
-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view
background = display.newImageRect( "Images/bg.jpg", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
total=display.newText("Score : 0",display.contentWidth * 0.5, 20, "Arial", 26)
total:setTextColor(000000)
countdown=display.newText(time_remain ,display.contentWidth * 0.9, 20, "Arial", 26)
countdown:setTextColor(000000)
life = display.newText("Life : 3 " ,display.contentWidth * 0.5, 50, "Arial", 26)
life:setTextColor(000000)
pauseBtn = display.newImage("Images/pause.png")
pauseBtn.x = display.contentWidth * 0.1
pauseBtn.y = display.contentHeight - 450
resumeBtn = display.newImage("Images/playb.png")
resumeBtn.x = display.contentWidth * 0.1
resumeBtn.y = display.contentHeight - 450
botwall=display.newImage("Images/tangan.png")
botwall.x = 160
botwall.y = 500
botwall:setFillColor(22,125,185,255)
botwall.type="botwall"
botwall.collision=collisionListener
physics.addBody(botwall,"static",{ density=100.0, friction=0.0, bounce=0.0} )
sceneGroup:insert(background)
sceneGroup:insert(total)
sceneGroup:insert(countdown)
sceneGroup:insert(life)
sceneGroup:insert(pauseBtn)
sceneGroup:insert(resumeBtn)
sceneGroup:insert(botwall)
resumeBtn.isVisible = false
pauseBtn:addEventListener("touch", pauseGame)
resumeBtn:addEventListener("touch", resumeGame)
botwall:addEventListener("collision",botwall)
dropMossie = timer.performWithDelay( 2000 , newMossie, -1 )
dropBee = timer.performWithDelay( 1800 , newBee, -1)
gametmr = timer.performWithDelay(1000, countDown, -1)
-- Initialize the scene here.
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is still off screen (but is about to come on screen).
elseif ( phase == "did" ) then
-- Called when the scene is now on screen.
-- Insert code here to make the scene come alive.
-- Example: start timers, begin animation, play audio, etc.
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is on screen (but is about to go off screen).
-- Insert code here to "pause" the scene.
-- Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == "did" ) then
-- Called immediately after scene goes off screen.
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
--physics.stop()
--timer.cancel(gametmr)
--pauseBtn:removeEventListener("touch", pauseGame)
--resumeBtn:removeEventListener("touch", resumeGame)
--botwall:removeEventListener("collision",botwall)
--bee:removeEventListener("touch",killIt)
--mossie:removeEventListener("touch",onTouch)
-- Called prior to the removal of scene's view ("sceneGroup").
-- Insert code here to clean up the scene.
-- Example: remove display objects, save state, etc.
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
---------------------------------------------------------------------------------
return scene
I suggest to make another composer scene for gameOverScreen (just like you did with these code block you post). Then do a composer.gotoScene(gameOver) read more here. And for the score I suggest that you make something like this.
The funtion handleButtonEvent is declared after you are creating a button widget. You can get the desired result by moving the function about the widget code.
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
composer.gotoScene ("menu")
end
end
local myButton = widget.newButton
{
left = 100,
top = 100,
id = "myButton",
label = "Menu",
onEvent = handleButtonEvent
}
myButton.isVisible = true
end
Hello all I am currently developing an application that I am going to use the perspective library with. I have imported the library and have written the correct code it seems but to no avail my camera is not working properly. I am attempting to get the camera to follow the main character you are moving around with the buttons. I added him and the background and a "tree" to the camera and set him as the focus but it still will not follow him. Here is my code please tell me what I have done wrong here and how to fix it.
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local perspective = require( "perspective" )
local camera = perspective.createView()
local physics = require( "physics" )
--physics.setDrawMode( "hybrid" )
local function start( event )
if( event.phase == "ended" ) then
end
end
local bg
local floor
local leftwall
local rightwall
local player
local button1
local button2
local pausebtn
local tree
local function b1( event )
if( event.phase == "ended" ) then
player:applyLinearImpulse( -.01, -.1 )
end
end
local function b2( event )
if( event.phase == "ended" ) then
player:applyLinearImpulse( .01, -.1 )
end
end
local function playerCollision( event )
if( event.phase == "began" ) then
storyboard.gotoScene( "gameover" )
end
end
local function pause( event )
if( event.phase == "ended" ) then
storyboard.showOverlay( "pause" )
physics.pause()
end
end
function scene:createScene( event )
local group = self.view
physics.start()
bg = display.newImage( "bg.png", display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight )
camera:add(bg, 3, false)
player = display.newImage( "player.png", display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight )
player.collision = playerCollision
camera:add(player, 1, true)
tree = display.newImage( "tree.png", 200, 200)
camera:add(tree, 2, false)
floor = display.newRect( 285, 375, 570, 1 )
button1 = display.newImage( "button1.png", 50, 275 )
button2 = display.newImage( "button2.png", 515, 275 )
leftwall = display.newRect( 0, -1000, 1, 5000 )
rightwall = display.newRect( 570, 300, 1, 5000 )
pausebtn = display.newImage( "pausebtn.png", 540, 30 )
-- Physics
physics.addBody( player )
physics.addBody( floor )
floor.bodyType = "static"
physics.addBody( rightwall )
rightwall.bodyType = "static"
physics.addBody( leftwall )
leftwall.bodyType = "static"
group:insert(bg)
group:insert(player)
group:insert(floor)
group:insert(button1)
group:insert(button2)
group:insert(rightwall)
group:insert(leftwall)
group:insert(pausebtn)
group:insert(tree)
end
function scene:enterScene( event )
print( "game" )
button1:addEventListener( "touch", b1 )
button2:addEventListener( "touch", b2 )
player:addEventListener( "collision", playerCollision )
pausebtn:addEventListener( "touch", pause )
end
function scene:exitScene()
player = nil
camera:cancel()
end
function scene:destroyScene( event )
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
Looks like you are missing the call to camera:track() (which should probably go in the enterScene handler). You might also need camera:setBounds(false).
If this still doesn't fix issue, remove all code from your post that is not required in order to duplicate the problem. If you can boil it down to a small example that I can run, I can try and post update.