Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local physics = require("physics")
- physics.start(); physics.pause()
- local _W = display.contentWidth
- local _H = display.contentHeight
- -- used to change the scale as needed
- local myScale = 1
- local group = display.newGroup()
- -- set the scale of the group
- group.xScale = myScale
- group.yScale = myScale
- -- create a moving object for the sample
- local ship = display.newCircle(60, 60, 60)
- ship.x = 100
- ship.y = 100
- physics.addBody(ship, 'dynamic')
- group:insert(ship)
- -- create a lister so we can touch the ball to move it
- ship.myTouchListener = function(event)
- if event.phase == 'began' then
- event.target:setLinearVelocity(400, 0)
- end
- --phases(began, moved, ended)
- end
- ship:addEventListener( "touch", ship.myTouchListener )
- -- create ground for context
- for i = 1,100 do
- --local myRectangle[i] = {}
- local myRectangle = display.newRect(group, 50*i, _H - 100, 100, 100)
- myRectangle:setFillColor(math.random(100, 255), math.random(100, 255), math.random(100, 255), 255)
- physics.addBody(myRectangle, 'static')
- end
- -- todo:
- -- this is the function that needs tweaking to slide the screen back depending
- -- on which direction we move
- local screenCenter = display.contentWidth / 2
- local offset = 0
- local camChangeSpeed = 1
- local function moveCamera()
- -- check which way the ball is moving
- local myX, myY = ship:getLinearVelocity() --if ship.ve
- -- Find limit by speed
- local desiredOffset = myX / 4
- if desiredOffset < offset then offset = math.max( offset - camChangeSpeed, desiredOffset )
- elseif desiredOffset > offset then offset = math.min( offset + camChangeSpeed, desiredOffset ) ; end
- group.x = -ship.x + screenCenter - offset
- end
- -- move the group as the ship moves
- Runtime:addEventListener('enterFrame', moveCamera)
- -- begin the physics
- physics.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement