Hey
I have tried to add the ball to the layer from within my main.lua file but still the ball will outrun the moving screen. I attach the code bellow and maybe you will see something strange in my newbee way of handling this lime / tile editor / corona sdk stuff
[lua]display.setStatusBar(display.HiddenStatusBar)
– Load Lime
local lime = require(“lime”)
lime.enableScreenCulling()
– Load your map
local map = lime.loadMap(“bouncermap.tmx”)
– Create the visual
local visual = lime.createVisual(map)
local physical = lime.buildPhysical(map)
local physics = require(“physics”)
physics.start()
local layer = map:getTileLayer(“tile1”)
layer:addObject(ball)
local ballBody = { density=0.9, friction=1.0, bounce=0.3, radius=10 }
–local ball = display.newImage(‘ball.png’,100,-50)
local ball = display.newImage(“ball.png”,100,-50)
physics.addBody(ball, ballBody)
ball.isBall = true
ball.linearDamping = 0.3
ball.angularDamping = 0.8
ball.isBullet = true – force continuous collision detection, to stop really fast shots from passing through other balls
target = display.newImage( “target.png” )
target.x = ball.x
target.y = ball.y
target.alpha = 0
– Shoot the cue ball, using a visible force vector
local function ballShot( event )
local t = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Stop current cueball motion, if any
–t:setLinearVelocity( 0, 0 )
–t.angularVelocity = 0
target.x = t.x
target.y = t.y
startRotation = function()
target.rotation = target.rotation + 4
end
Runtime:addEventListener( “enterFrame”, startRotation )
local showTarget = transition.to( target, { alpha=0.4, xScale=0.4, yScale=0.4, time=200 } )
myLine = nil
elseif t.isFocus then
if “moved” == phase then
if ( myLine ) then
myLine.parent:remove( myLine ) – erase previous line, if any
end
myLine = display.newLine( t.x,t.y, event.x,event.y )
myLine:setColor( 255, 255, 255, 80 )
myLine.width = 8
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
local stopRotation = function()
Runtime:removeEventListener( “enterFrame”, startRotation )
end
local hideTarget = transition.to( target, { alpha=0, xScale=1.0, yScale=1.0, time=200, onComplete=stopRotation } )
if ( myLine ) then
myLine.parent:remove( myLine )
end
physics.start()
– Strike the ball!
t:applyForce( (t.x - event.x)*2, (t.y - event.y)*2, t.x, t.y )
print(event.x)
end
end
– Stop further propagation of touch event
return true
end
map:setFocus(ball)
ball:addEventListener(“touch”, ballShot)
local onUpdate = function(event)
map:update(event)
end
Runtime:addEventListener(“enterFrame”, onUpdate)[/lua] [import]uid: 22737 topic_id: 5038 reply_id: 20632[/import]