Hi, at the moment, my game does not have any errors in it, but what I wanted to figure out was how to increase the touch of the soccerball without causing an issue with physical contact of the surrounding area. I am using corona lime with a tiled map. The ball is 32x32 pixels and I want to only create the size of the touch for the player because people are having issues touching the ball because of the size.
The second thing I wanted to figure out was causing the ball to respawn at the beginning when it goes off screen.
[lua]display.setStatusBar( display.HiddenStatusBar )
system.activate( “multitouch” )
display.setStatusBar( display.HiddenStatusBar )
– Load Lime
local lime = require(“lime”)
require(“physics”)
physics.start()
– Load your map
local map = lime.loadMap(“LevelOne.tmx”)
local onPlayerSpawnObject = function(object)
local layer = map:getTileLayer(“sBall”)
player = display.newImage(layer.group, “soccerBall2.png”)
player.x = object.x
player.y = object.y
physics.addBody(player, { density = 1.0, friction = 0.3, bounce = 0.2, radius=14 })
player.rotation = math.random( 1, 800 )
– player.linearDamping = 0.4
– player.angularDamping = 0.6
end
map:addObjectListener(“PlayerSpawn”, onPlayerSpawnObject)
– Create the visual
local visual = lime.createVisual(map)
local back = display.newRect( map:getVisual(), 0, 0, map:getVisual().contentWidth, map:getVisual().contentHeight )
back:setFillColor(165, 210, 255)
back:toBack()
– Build the physics
local physical = lime.buildPhysical(map)
–local onTouch = function( event )
– Drag the map
–map:drag( event )
–end
–Runtime:addEventListener( “touch”, onTouch )
local function onCollision(self, event )
if ( event.phase == “began” ) then
if event.other.IsGround then
player.canJump = true
end
elseif ( event.phase == “ended” ) then
if event.other.IsGround then
player.canJump = false
end
end
end
player.collision = onCollision
player:addEventListener( “collision”, player )
local onTouch = function(event)
if player.canJump then
player:applyLinearImpulse(0 , -8, player.x, player.y)
end
end
player:addEventListener(“tap”, onTouch)
–Runtime:addEventListener(“accelerometer”, onTouch)
local onAir = function(event)
if player.canJump==false then
player:applyLinearImpulse(6 , -2, player.x, player.y)
end
end
player:addEventListener(“tap”, onAir)
– Set the maps focus to the circle.
map:setFocus( player )
local onUpdate = function( event )
– Update the map. Needed for using map:setFocus()
map:update( event )
end
Runtime:addEventListener( “enterFrame”, onUpdate )
–function ballf(event)
–if player.canJump then
– vx, vy = player:getLinearVelocity()
–player:setLinearVelocity( -vx, -vy )
–end
–end
–player:addEventListener(“touch”, ballf)[/lua]
[import]uid: 96127 topic_id: 18660 reply_id: 318660[/import]
[import]uid: 84637 topic_id: 18660 reply_id: 71712[/import]