Thanks for you help, Nail!
I have changed the code to this, but now all I get is a wallpaper and nothing else… it’s kinda strange:
[code]
local perspective = require(“perspective”)
local camera = perspective.createView()
– physics.setDrawMode(“hybrid”)
local physics = require(“physics”)
physics.start()
physics.setScale( 60 )
physics.setGravity(0, 10)
display.setStatusBar( display.HiddenStatusBar )
local background = display.newImage( “images/clouds.png”, true )
– Create player and set location
local player = display.newImage(“images/fred.png”)
player.x = display.contentWidth / 2
player.y = display.contentHeight / 6
– Turn player into physics body
physics.addBody(player, { radius = 30 } );
– Create walls on the left and right
local leftWall = display.newRect (0, 0, 1, display.contentHeight);
local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight);
– Add physics to the walls. They will not move so they will be static
physics.addBody (leftWall, “static”, { bounce = 0.1 } );
physics.addBody (rightWall, “static”, { bounce = 0.1 } );
– Floor with physics
local bottomFloor = display.newRect(0, 500, display.contentWidth, 20)
physics.addBody(bottomFloor, “static”, { bounce = 1.0, } )
_W = display.contentWidth;
_H = display.contentHeight;
local lineLengthConstraint = 128
local lines = {}
local function getLength(x1, x2, y1, y2)
local x = x1 - x2
local y = y1 - y2
local length = math.sqrt(x*x + y*y)
return length
end
local function drawLine(event)
if event.phase == “began” then
– inTouch state.
inTouch = true
– X/Y Coordinates of initial touch.
initialX = event.x
initialY = event.y
– Create our line.
ourLine = display.newLine(initialX, initialY, initialX, initialY+getLength(initialX, event.x, initialY, event.y))
ourLine:setColor(0,255,0)
ourLine.width = 8
ourLine.rotation = math.deg(math.atan2(event.y - initialY, event.x - initialX)) - 90
elseif event.phase == “moved” and inTouch then
– Recreate our line, in the case that it is shorter than the length constraint.
if getLength(initialX, event.x, initialY, event.y) <= lineLengthConstraint then
– Remove old version of our line.
display.remove(ourLine)
ourLine = nil
– Create new version of our line.
ourLine = display.newLine(initialX, initialY, initialX, initialY+getLength(initialX, event.x, initialY, event.y))
ourLine:setColor(0,255,0)
ourLine.width = 8
– Store limited line length.
limitedLineLength = getLength(initialX, event.x, initialY, event.y)
– Physics
–local physShape = { (ourLine.width/2),0, (ourLine.width/2),limitedLineLength, -(ourLine.width/2),limitedLineLength, -(ourLine.width/2),0 }
–physics.addBody(ourLine, “static”, {bounce=1.0, shape=physShape})
end
– Set rotation of our line.
ourLine.rotation = math.deg(math.atan2(event.y - initialY, event.x - initialX)) - 90
elseif event.phase == “ended” and inTouch then
– inTouch state.
inTouch = false
– Physics
local physShape = { (ourLine.width/2),0, (ourLine.width/2),limitedLineLength, -(ourLine.width/2),limitedLineLength, -(ourLine.width/2),0 }
physics.addBody(ourLine, “static”, {bounce=1.5, shape=physShape})
– Remove line from the screen when there’s one or more stored in the table.
if #lines >= 1 then
for i=1,#lines do
display.remove(lines[i])
lines[i] = nil
end
end
– Store our line in a table, just in case we need to reference or remove it later.
i = #lines+1
lines[i] = ourLine
camera:add(lines[i], 1, false)
end
end
Runtime:addEventListener(“touch”, drawLine)
camera.x, camera.y = 100, 100
camera:add(player, 1, false)
camera:add(rightWall, 1, true)
camera:add(leftWall, 1, true)
camera:add(bottomFloor, 1, true)
camera:setFocus(player)
– camera.offsetX, camera.offsetY = 150, 150
camera:setBounds(0, 0, 0, 1000000000)
camera.damping = 20
camera:track()
[/code] [import]uid: 188277 topic_id: 35062 reply_id: 139742[/import]