Collecting Items in Game + Problem

Thank you for your support, I tried it but unfortunately it is not working. Did I miss something - here is my code:

[lua]module(…, package.seeall)

display.setStatusBar( display.HiddenStatusBar ) – Hide Status Bar

function new()

local Level1 = display.newGroup()

– REQUIRED EXTERNAL LIBRARIES
local ui = require(“ui”)
local scaleFactor = 1
local physicsData = (require “Physics”).physicsData(scaleFactor)

– REQUIRED PHYSICS
local physics = require( “physics” )
physics.start()
physics.setGravity( 0, 9.5 )
physics.setDrawMode( “hybrid” )
–physics.setDrawMode( “debug” )

–GAME SEETTINGS
local gameIsActive = false
local levelCompleted = false

–OBJECTS
local Platform1
local Platform2
local ground
local leftWall
local rightWall
local Player
local topWall

– HUD OBJECTS
local Background
local GameOverDisplay
local tryAgainBtn
local menuBtn
local menuBtn1
local GameOverImage
local PauseOverlay
local ResetLevelBtn

–==*********************************************************************==–
–==*********************************************************************==–
–==*********************************************************************==–
–==*********************************************************************==–
–Background
Background = display.newImageRect(“Background.png”, 480, 320 )
Background.x = 240
Background.y = 160
Level1:insert(Background)

–Platform 2

Platform2 = display.newImageRect(“PFinal.png”, 205, 36)
physics.addBody(Platform2, “static”, physicsData:get(“PFinal”))
Platform2.x = 363
Platform2.y = 220
Platform2.myName = “Platform2”
Level1:insert(Platform2)

–Platform 1
Platform1 = display.newImageRect(“PFinalS.png”, 205, 36)
Platform1.x = 111
Platform1.y = 265
Platform1.myName = “Platform1”
physics.addBody(Platform1, “static”, physicsData:get(“PFinalS”))
Level1:insert(Platform1)

–Ground
ground = display.newRect( 0, 0, 479, 1 )
ground.x = 240
ground.y = 321
physics.addBody(ground, “static”, {bounce=0})
ground.myName = “ground”
Level1:insert(ground)
– create wall objects
topWall = display.newRect( 0, 0, display.contentWidth, 1)
topWall.alpha = 0
topWall.myName = “topWall”
leftWall = display.newRect( 0, 0, 1, display.contentHeight )
leftWall.alpha = 0
leftWall.myName = “leftWall”
rightWall = display.newRect( display.contentWidth - 1, 0, 1, display.contentHeight )
rightWall.myName = “rightWall”
rightWall.alpha = 0

– make them physics bodies
physics.addBody(topWall, “static”, {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})
physics.addBody(leftWall, “static”, {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})
physics.addBody(rightWall, “static”, {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})

Level1:insert(topWall)
Level1:insert(leftWall)
Level1:insert(rightWall)

Player = display.newImageRect(“Player1.png”, 40, 40 )
physics.addBody( Player, “dynamic”, physicsData:get(“Player1”))
Player.x = 40
Player.y = 100
Player.myName = “Player”
Player.isFixedRotation = true
Player.iAwake = true
Player.isBullet = true
Level1:insert(Player)

function Player:collision (event)
if event.phase == “ended” and event.other.myName ~= “coin” and event.other.myName ~= “leftWall” and event.other.myName ~= “rightWall” and event.other.myName ~= “topWall” then
Player:applyForce(0,-40, Player.x, Player.y)

print(“Player Collided With Platform”)

end

end
Player:addEventListener(“collision”, Player)
local function doGameCompleted()
levelCompleted = true
print(“Level 1 was completed”)

end

– Moves the player along the x-axis

function onTilt( event )
physics.setGravity( ( 9.2 * event.xGravity ), 0 )
end

Runtime:addEventListener( “accelerometer”, onTilt )

–Coins to collect - total - 5
local coin = {}
coin[1] = display.newImageRect(“coin.png”, 20, 20)
coin[1].x = 160
coin[1].y = 238
coin[1].myName = “coin”
coin[2] = display.newImageRect(“coin.png”, 20, 20)
coin[2].x = 180
coin[2].y = 238
coin[2].myName = “coin”
coin[3] = display.newImageRect(“coin.png”, 20, 20)
coin[3].x = 200
coin[3].y = 238
coin[3].myName = “coin”

coin[4] = display.newImageRect(“coin.png”, 20, 20)
coin[4].x = 370
coin[4].y = 192
coin[4].myName = “coin”

coin[5] = display.newImageRect(“coin.png”, 20, 20)
coin[5].x = 390
coin[5].y = 192
coin[5].myName = “coin”

for i = 1, #coin do
physics.addBody(coin[i], “static”, {isSensor = true})
Level1:insert(coin[i])
end

local function onCollision( event )
if ( event.phase == “began” ) then

if event.object1.myName == “Player” and event.object2.myName == “coin” then
event.object2.alpha = 0.001

end

elseif ( event.phase == “ended” ) then

if event.object1.myName == “Player” and event.object2.myName == “coin” then
event.object2:removeSelf()
event.object2 = nil

CoinCollected = CoinCollected + 1

if (CoinCollected == CoinsToCollect) then
levelCompleted = true
doGameCompleted()
end

quotaText.text = " " … tostring(CoinCollected) …" / " … tostring(CoinsToCollect)
quotaText.xScale = 0.5; quotaText.yScale = 0.5
quotaText.x = 55
quotaText.y = 10
quotaText.size = 50

end

end
end

Runtime:addEventListener( “collision”, onCollision )

– Coin Collect Count

local CoinCollected = CoinsToCollect
quotaText = display.newText( “0 / 5”, 50, 309, “Arial”, 28 )
quotaText.text = " 0 / " … tostring(CoinsToCollect)
quotaText.xScale = 0.5; quotaText.yScale = 0.5
quotaText.x = 30
quotaText.y = 10
quotaText.size = 50

Level1:insert( quotaText )

–Level 1 StartModule

local levelNum = levelNumber
local levelDisplay = display.newText( “Level”, 240, 95, “Arial”, 84 )
levelDisplay:setTextColor( 220, 294, 220, 220 )
levelDisplay.text = "LEVEL " … tostring(levelNum)
levelDisplay.xScale = 0.05; levelDisplay.yScale = 0.05
levelDisplay.alpha = 0.75
levelDisplay.size = 180
levelDisplay.x = 240; levelDisplay.y = 100

Level1:insert( levelDisplay)

local hideLevelDisplay = function()
local removeIt = function()
levelDisplay:removeSelf()
levelDisplay = nil
end

local newY = levelDisplay.y - 50

transition.to( levelDisplay, { time=2000, alpha=0, y=newY, onComplete=removeIt } )
end

transition.to( levelDisplay, { time=500, xScale=0.5, yScale=0.5, onComplete=hideLevelDisplay } )

unloadMe = function()

physics.stop()

– STOP Timers, Runtime Listeners, Transitions, etc.
Player:addEventListener(“collision”, Player)

Runtime:removeEventListener( “collision”, onCollision )
Runtime:removeEventListener( “system”, onSystem )

hideLevelDisplay = nil
removeIt = nil

[/lua] Thank you very much in advance, I really appreciate it. [import]uid: 122802 topic_id: 22117 reply_id: 91988[/import]

Try this for Level1.lua

  
module(..., package.seeall)  
  
display.setStatusBar( display.HiddenStatusBar ) -- Hide Status Bar  
  
function new()   
  
local Level1 = display.newGroup()  
  
-- REQUIRED EXTERNAL LIBRARIES  
local ui = require("ui")  
local scaleFactor = 1  
local physicsData = (require "Physics").physicsData(scaleFactor)  
  
-- REQUIRED PHYSICS  
local physics = require( "physics" )  
physics.start()  
physics.setGravity( 0, 9.2 )  
--physics.setDrawMode( "hybrid" )  
--physics.setDrawMode( "debug" )  
physics.setDrawMode( "normal" )  
  
  
--GAME SEETTINGS  
local gameIsActive = false  
local levelCompleted = false  
  
--OBJECTS  
local Platform1  
local Platform2  
local ground  
local leftWall  
local rightWall  
local Player  
local topWall  
  
-- HUD OBJECTS  
local Background  
local GameOverDisplay  
local tryAgainBtn  
local menuBtn  
local menuBtn1  
local GameOverImage  
local PauseOverlay  
local ResetLevelBtn  
  
  
  
--==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*==--  
--==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*==--   
--==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*==--  
--==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*==--  
--Background  
 Background = display.newImageRect("Background.png", 480, 320 )  
Background.x = 240  
Background.y = 160  
Level1:insert(Background)  
  
--Platform 2  
  
Platform2 = display.newImageRect("PFinal.png", 205, 36)  
physics.addBody(Platform2, "static", physicsData:get("PFinal"))  
Platform2.x = 363  
Platform2.y = 220  
Platform2.myName = "Platform2"  
  
--Platform 1  
Platform1 = display.newImageRect("PFinalS.png", 205, 36)  
Level1:insert(Platform1)  
Platform1.x = 111  
Platform1.y = 265  
Platform1.myName = "Platform1"  
physics.addBody(Platform1, "static", physicsData:get("PFinalS"))  
  
--Ground   
ground = display.newRect( 0, 0, 479, 1 )  
ground.x = 240  
ground.y = 321  
physics.addBody(ground, "static", {bounce=0})  
ground.myName = "ground"  
Level1:insert(ground)  
-- create wall objects  
topWall = display.newRect( 0, 0, display.contentWidth, 1)  
Level1:insert(topWall)  
topWall.alpha = 0  
topWall.myName = "topWall"  
leftWall = display.newRect( 0, 0, 1, display.contentHeight )  
Level1:insert(leftWall)  
leftWall.alpha = 0  
leftWall.myName = "leftWall"  
rightWall = display.newRect( display.contentWidth - 1, 0, 1, display.contentHeight )  
Level1:insert(rightWall)  
rightWall.myName = "rightWall"  
rightWall.alpha = 0  
  
-- make them physics bodies  
physics.addBody(topWall, "static", {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})  
physics.addBody(leftWall, "static", {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})  
physics.addBody(rightWall, "static", {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})  
  
Player = display.newImageRect("Player1.png", 40, 40 )  
Level1:insert(Player)  
physics.addBody( Player, "dynamic", physicsData:get("Player1"))  
Player.x = 40  
Player.y = 100  
Player.myName = "Player"  
Player.isFixedRotation = true  
Player.iAwake = true  
Player.isBullet = true  
function Player:collision (event)  
 if event.phase == "ended" and event.other.myName ~= "coin" and event.other.myName ~= "leftWall" and event.other.myName ~= "rightWall" and event.other.myName ~= "topWall" then   
 Player:applyForce(0,-40, Player.x, Player.y)  
  
 print("Player Collided With Platform")  
  
  
  
  
  
 end  
  
  
end  
Player:addEventListener("collision", Player)  
local function doGameCompleted()  
 levelCompleted = true  
 print("Level 1 was completed")   
  
 end   
  
  
  
function onTilt( event )  
 physics.setGravity( ( 9.2 \* event.xGravity ), ( 9.2 \* event.yGravity ) )  
end  
   
Runtime:addEventListener( "accelerometer", onTilt )   
  
  
  
--Corns to collect - total - 5  
local coin = {}  
 coin[1] = display.newImageRect("coin.png", 20, 20)  
 Level1:insert(coin[1])  
 coin[1].x = 160  
 coin[1].y = 238  
 coin[1].myName = "coin"  
 coin[2] = display.newImageRect("coin.png", 20, 20)  
 Level1:insert(coin[2])  
 coin[2].x = 180  
 coin[2].y = 238  
 coin[2].myName = "coin"  
 coin[3] = display.newImageRect("coin.png", 20, 20)  
 Level1:insert(coin[3])  
 coin[3].x = 200  
 coin[3].y = 238  
 coin[3].myName = "coin"  
  
 coin[4] = display.newImageRect("coin.png", 20, 20)  
 Level1:insert(coin[4])  
 coin[4].x = 370  
 coin[4].y = 192  
 coin[4].myName = "coin"  
  
 coin[5] = display.newImageRect("coin.png", 20, 20)  
 Level1:insert(coin[5])  
 coin[5].x = 390  
 coin[5].y = 192  
 coin[5].myName = "coin"  
  
  
 for i = 1, #coin do  
 physics.addBody(coin[i], "static", {isSensor = true})  
end  
  
  
  
  
 local function onCollision( event )  
 if ( event.phase == "began" ) then  
   
 if event.object1.myName == "Player" and event.object2.myName == "coin" then  
 event.object2.alpha = 0.001  
  
 end  
   
 elseif ( event.phase == "ended" ) then  
   
 if event.object1.myName == "Player" and event.object2.myName == "coin" then  
 event.object2:removeSelf()  
 event.object2 = nil  
  
 CoinCollected = CoinCollected + 1  
  
  
 if (CoinCollected == CoinsToCollect) then  
 levelCompleted = true  
 doGameCompleted()  
 end  
  
  
  
 quotaText.text = " " .. tostring(CoinCollected) .." / " .. tostring(CoinsToCollect)  
 quotaText.xScale = 0.5; quotaText.yScale = 0.5  
 quotaText.x = 55  
 quotaText.y = 10  
 quotaText.size = 50  
  
  
 end  
   
 end  
 end  
  
 Runtime:addEventListener( "collision", onCollision )  
  
  
  
  
-- Coin Collect Count   
  
local CoinCollected = CoinsToCollect  
 quotaText = display.newText( "0 / 5", 50, 309, "Arial", 28 )  
 quotaText.text = " 0 / " .. tostring(CoinsToCollect)  
 quotaText.xScale = 0.5; quotaText.yScale = 0.5  
 quotaText.x = 30  
 quotaText.y = 10  
 quotaText.size = 50  
  
 Level1:insert( quotaText )  
  
  
  
  
  
  
  
--Level 1 StartModule   
  
local levelNum = levelNumber  
 local levelDisplay = display.newText( "Level", 240, 95, "Arial", 84 )  
 levelDisplay:setTextColor( 220, 294, 220, 220 )  
 levelDisplay.text = "LEVEL " .. tostring(levelNum)  
 levelDisplay.xScale = 0.05; levelDisplay.yScale = 0.05  
 levelDisplay.alpha = 0.75  
 levelDisplay.size = 180  
 levelDisplay.x = 240; levelDisplay.y = 100  
  
 Level1:insert( levelDisplay)  
  
 local hideLevelDisplay = function()  
 local removeIt = function()  
 levelDisplay:removeSelf()  
 levelDisplay = nil  
 end  
  
 local newY = levelDisplay.y - 50  
  
 transition.to( levelDisplay, { time=2000, alpha=0, y=newY, onComplete=removeIt } )  
 end  
  
 transition.to( levelDisplay, { time=500, xScale=0.5, yScale=0.5, onComplete=hideLevelDisplay } )  
  
  
  
  
  
 unloadMe = function()  
  
  
 physics.stop()  
  
 -- STOP Timers, Runtime Listeners, Transitions, etc.  
 Player:addEventListener("collision", Player)  
  
 Runtime:removeEventListener( "collision", onCollision )  
 Runtime:removeEventListener( "system", onSystem )  
  
  
  
 hideLevelDisplay = nil  
 removeIt = nil  
  
  
  
 end  
 return Level1  
 end   
  

I also changed tilt code line. But, you will need to tweak physics and tilt controls to make play control better.

physics.setGravity( ( 9.2 \* event.xGravity ), ( 9.2 \* event.yGravity ) )  

Let me know if this works and if you have any more issues. I hope this helps.

[import]uid: 38820 topic_id: 22117 reply_id: 91993[/import]

Hi glennbjr,

Thank you very much for taking your time to help me. Unfortunately the code you have posted above doesn’t seem to work either. I have found out that if I switch the game character out with another character which is more rectangular. That seems to solve one of the problems(I will like to keep my original character, which isn’t so rectangular than the other one that worked, is this possible?) The problem I refer to is where the character stops jumping when it is colliding with the coins. Or could the reason for the issues be that I use the “Corona Remote App” to move the character around by the devices accelerometer on the Corona Simulator?

Here is my project - one with the rectangular character and one with the original character.

http://www.mediafire.com/?711y6z2am8x10y1

Thank you very much for your help in advance
[import]uid: 122802 topic_id: 22117 reply_id: 92029[/import]

Hi Corona Community

I am pretty much stuck with my project because of this problem and I will really appreciate if someone can help me to solve these problem explained above, so I can get my project up and running again. I wanna thank every body who have tried to help me so far.

I have made a video, which it’s showcasing the problem.

http://www.youtube.com/watch?v=Zo_hBUUTw8c

Thank you very much for the support. [import]uid: 122802 topic_id: 22117 reply_id: 92748[/import]

This works pretty good. Try the code below.

[code]

module(…, package.seeall)

display.setStatusBar( display.HiddenStatusBar ) – Hide Status Bar

function new()

local Level1 = display.newGroup()

– REQUIRED EXTERNAL LIBRARIES
local ui = require(“ui”)
local scaleFactor = 1
local physicsData = (require “Physics”).physicsData(scaleFactor)

– REQUIRED PHYSICS
local physics = require( “physics” )
physics.start()
physics.setGravity( 0, 9.2 )
–physics.setDrawMode( “hybrid” )
–physics.setDrawMode( “debug” )
physics.setDrawMode( “normal” )

–GAME SEETTINGS
local gameIsActive = false
local levelCompleted = false

–OBJECTS
local Platform1
local Platform2
local ground
local leftWall
local rightWall
local Player
local topWall

– HUD OBJECTS
local Background
local GameOverDisplay
local tryAgainBtn
local menuBtn
local menuBtn1
local GameOverImage
local PauseOverlay
local ResetLevelBtn

–==*********************************************************************==–
–==*********************************************************************==–
–==*********************************************************************==–
–==*********************************************************************==–
–Background
Background = display.newImageRect(“Background.png”, 480, 320 )
Background.x = 240
Background.y = 160
Level1:insert(Background)

–Platform 2

Platform2 = display.newImageRect(“PFinal.png”, 205, 36)
physics.addBody(Platform2, “static”, {bounce=0,density=0.1,friction=0})
Platform2.x = 363
Platform2.y = 220
Platform2.myName = “Platform”

–Platform 1
Platform1 = display.newImageRect(“PFinalS.png”, 205, 36)
Level1:insert(Platform1)
Platform1.x = 111
Platform1.y = 265
Platform1.myName = “Platform”
physics.addBody(Platform1, “static”, {bounce=0,density=0.1,friction=0})

–Ground
ground = display.newRect( 0, 0, 479, 1 )
ground.x = 240
ground.y = 321
physics.addBody(ground, “static”, {bounce=0})
ground.myName = “ground”
Level1:insert(ground)
– create wall objects
topWall = display.newRect( 0, 0, display.contentWidth, 1)
Level1:insert(topWall)
topWall.alpha = 0
topWall.myName = “topWall”
leftWall = display.newRect( 0, 0, 1, display.contentHeight )
Level1:insert(leftWall)
leftWall.alpha = 0
leftWall.myName = “leftWall”
rightWall = display.newRect( display.contentWidth - 1, 0, 1, display.contentHeight )
Level1:insert(rightWall)
rightWall.myName = “rightWall”
rightWall.alpha = 0

– make them physics bodies
physics.addBody(topWall, “static”, {density = 0.1, friction = 0, bounce = 0.1, isSensor = false})
physics.addBody(leftWall, “static”, {density = 0.1, friction = 0, bounce = 0.1, isSensor = false})
physics.addBody(rightWall, “static”, {density = 0.1, friction = 0, bounce = 0.1, isSensor = false})

Player = display.newImageRect(“Player1.png”, 40, 40 )
Level1:insert(Player)
physics.addBody( Player, “dynamic”, {bounce=0,density=0.1,friction=0})
Player.x = 40
Player.y = 100
Player.myName = “Player”
Player.isFixedRotation = true
Player.iAwake = true
Player.isBullet = true
Player.vx, Player.vy = 0
local function doGameCompleted()
levelCompleted = true
print(“Level 1 was completed”)

end

function onTilt( event )
physics.setGravity( ( 9.2 * event.xGravity ), 9.2)
end
Runtime:addEventListener( “accelerometer”, onTilt )

–Corns to collect - total - 5
local coin = {}
coin[1] = display.newImageRect(“coin.png”, 20, 20)
Level1:insert(coin[1])
coin[1].x = 160
coin[1].y = 238
coin[1].myName = “coin”
coin[2] = display.newImageRect(“coin.png”, 20, 20)
Level1:insert(coin[2])
coin[2].x = 180
coin[2].y = 238
coin[2].myName = “coin”
coin[3] = display.newImageRect(“coin.png”, 20, 20)
Level1:insert(coin[3])
coin[3].x = 200
coin[3].y = 238
coin[3].myName = “coin”

coin[4] = display.newImageRect(“coin.png”, 20, 20)
Level1:insert(coin[4])
coin[4].x = 370
coin[4].y = 192
coin[4].myName = “coin”

coin[5] = display.newImageRect(“coin.png”, 20, 20)
Level1:insert(coin[5])
coin[5].x = 390
coin[5].y = 192
coin[5].myName = “coin”

for i = 1, #coin do
physics.addBody(coin[i], “static”, {isSensor = true})
end

local function onCollision( event )
local function playerBounce()
Player:applyForce(0,-40, Player.x, Player.y)
end

if event.phase == “began” then

– player bounce
Player.vx, Player.vy = Player:getLinearVelocity()
if event.object1.myName == “Platform” and event.object2.myName == “Player” then
Player:setLinearVelocity( Player.vx, 0 )
timer.performWithDelay(2, playerBounce)
print(“Player Collided With Platform”)
end
if event.object2.myName == “Platform” and event.object1.myName == “Player” then
Player:setLinearVelocity( Player.vx, 0 )
timer.performWithDelay(2, playerBounce)
print(“Player Collided With Platform”)
end

if event.object1.myName == “Player” and event.object2.myName == “coin” then
event.object2.alpha = 0.001
end
end

if event.phase == “ended” then
if event.object1.myName == “Player” and event.object2.myName == “coin” then
event.object2:removeSelf()
event.object2 = nil
CoinCollected = CoinCollected + 1
if (CoinCollected == CoinsToCollect) then
levelCompleted = true
doGameCompleted()
end
quotaText.text = " " … tostring(CoinCollected) …" / " … tostring(CoinsToCollect)
quotaText.xScale = 0.5; quotaText.yScale = 0.5
quotaText.x = 55
quotaText.y = 10
quotaText.size = 50
end
if event.object2.myName == “Player” and event.object1.myName == “coin” then
event.object1:removeSelf()
event.object1 = nil
CoinCollected = CoinCollected + 1
if (CoinCollected == CoinsToCollect) then
levelCompleted = true
doGameCompleted()
end
quotaText.text = " " … tostring(CoinCollected) …" / " … tostring(CoinsToCollect)
quotaText.xScale = 0.5; quotaText.yScale = 0.5
quotaText.x = 55
quotaText.y = 10
quotaText.size = 50
end
end
end
Runtime:addEventListener( “collision”, onCollision )

– Coin Collect Count

local CoinCollected = CoinsToCollect
quotaText = display.newText( “0 / 5”, 50, 309, “Arial”, 28 )
quotaText.text = " 0 / " … tostring(CoinsToCollect)
quotaText.xScale = 0.5; quotaText.yScale = 0.5
quotaText.x = 30
quotaText.y = 10
quotaText.size = 50
Level1:insert( quotaText )
–Level 1 StartModule

local levelNum = levelNumber
local levelDisplay = display.newText( “Level”, 240, 95, “Arial”, 84 )
levelDisplay:setTextColor( 220, 294, 220, 220 )
levelDisplay.text = "LEVEL " … tostring(levelNum)
levelDisplay.xScale = 0.05; levelDisplay.yScale = 0.05
levelDisplay.alpha = 0.75
levelDisplay.size = 180
levelDisplay.x = 240; levelDisplay.y = 100
Level1:insert( levelDisplay)

local hideLevelDisplay = function()
local removeIt = function()
levelDisplay:removeSelf()
levelDisplay = nil
end

local newY = levelDisplay.y - 50
transition.to( levelDisplay, { time=2000, alpha=0, y=newY, onComplete=removeIt } )
end

transition.to( levelDisplay, { time=500, xScale=0.5, yScale=0.5, onComplete=hideLevelDisplay } )

unloadMe = function()
physics.stop()

– STOP Timers, Runtime Listeners, Transitions, etc.
Player:addEventListener(“collision”, Player)

Runtime:removeEventListener( “collision”, onCollision )
Runtime:removeEventListener( “system”, onSystem )

hideLevelDisplay = nil
removeIt = nil
end
return Level1
end

[/code] [import]uid: 38820 topic_id: 22117 reply_id: 92818[/import]

Hi glennbjr

Thank you very much for the code, it seem to work very well with the rectangular physics shape. But is it possible to use the characters body shape (Which I have defined via a physics editor) instead of the normal square physics shape? I want to use:

This code
[lua]physics.addBody( Player, “dynamic”, physicsData:get(“Player1”)[/lua]

Instead of this code
[lua]physics.addBody(Player, “dynamic”, {bounce=0,density=0.1,friction=0})[/lua]

When I use the characters body shape (instead of the rectangular shape) the issues returns. The reason why I want to use the characters shape, is because in my game the character should have the possibility to fall between platforms and this is not possible, due to fact that the rectangular shape includes “free space in the corners”, which is colliding with the platforms when it falls and I don’t want this to happen, (only the characters physic shape, should be used). I hope you can help me with this frustrating issue.
Many thanks in advance. [import]uid: 122802 topic_id: 22117 reply_id: 93608[/import]

You’re probably better off making the player a circle because your complex physics shape is causing you problems.

physics.addBody( Player, "dynamic", {bounce=0,density=0.14,friction=0, radius = 19 } )  

[import]uid: 38820 topic_id: 22117 reply_id: 93615[/import]

Hi glennbjr

First I wanna thank you very much for your support and the quick response.

The circular physics shape dosen’t seem to work either with the code you have posted above (post #24). I get the same issues that I get when I use the characters body shape. Is there a way to solve this, so I can use the circular physics shape instead of the rectangular?

Best regards

Se460
[import]uid: 122802 topic_id: 22117 reply_id: 93829[/import]

Anybody that has an idea how I can fix this problem, so I can use a circle as my physics shape, without it is sticking to the walls?

I really appreciate your help, thank you so much in advance

[import]uid: 122802 topic_id: 22117 reply_id: 95088[/import]

Post #26 looks good, are you sure the object you are trying to add physics to is called exactly ‘Player’ ?

The entire part that gives them circular collision instead of rectangular is the ‘radius’ part.

[import]uid: 77199 topic_id: 22117 reply_id: 95165[/import]

Hi hatethinkingofnames and community

Yes the object I am trying to add physics to is called “Player”.

The code at post #26, is working fine, my object is getting the circular phyics shape, but I start to get the issues that are explained above (The character is sticking to the walls and so on, I want to eliminate that).

I am using the code that glennbjr have posted above (post number #24) and every thing is working fine with the rectangular physics shape, but as soon as I change the physics shape to a circle I get the issues. Is there a way to fix this, so I can use the circular phyics shape instead of the rectangular? Thank you very much for all the help I have got so far and thank you in advance.
[import]uid: 122802 topic_id: 22117 reply_id: 95203[/import]