I’m trying to get the camera to follow “egg_1” (as shown below). However, it doesn’t work. What would be the problem? Also, I’m trying to add a point system which allows the user to receive certain amounts of point based on the falling distance. Is there any code for that too?
[lua] – SYSTEM Setting
module(…, package.seeall)
– SET UP
function gameplay()
display.setStatusBar( display.HiddenStatusBar )
setUpStartScreen()
end
– Start Screen
function setUpStartScreen()
local ui = require ( “ui” )
setUpStartGame = display.newGroup()
local background = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
background:setFillColor(102, 153, 153)
setUpStartGame:insert(background)
game_start_btn = display.newImageRect( “images/gamestart_orange.png”, 240, 85 )
game_start_btn.x = display.contentWidth / 2
game_start_btn.y = display.contentHeight - display.contentHeight / 2
setUpStartGame:insert(game_start_btn)
game_start_btn:addEventListener(“touch”, game_start_setup)
return true
end
function game_start_setup()
setUpStartGame:removeSelf()
– Save and Load System
require( “ice” )
local scores = ice:loadBox( “scores” )
– Require Moving Cameria
local camera = display.newGroup();
camera.y = 0
– ADD PHYSICS
local physics = require “physics”
physics.setGravity(0,0)
– PHYSICS: TILTING
local function onTilt( event )
physics.setGravity( 10 * event.xGravity, -10 * event.yGravity )
end
Runtime:addEventListener( “accelerometer”, onTilt )
physics.start( true )
local game_countdown = display.newGroup()
local background_1 = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
background_1:setFillColor(0, 0, 0)
camera:insert(background_1)
game_countdown:insert(background_1)
– Physic Drag Function
local function dragBody( event )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage()
if “began” == phase then
stage:setFocus( body, event.id )
body.isFocus = true
– Create a temporary touch joint and store it in the object for later reference
body.tempJoint = physics.newJoint( “touch”, body, event.x, event.y )
elseif body.isFocus then
if “moved” == phase then
– Update the joint to track the touch
body.tempJoint:setTarget( event.x, event.y )
elseif “ended” == phase or “cancelled” == phase then
stage:setFocus( body, nil )
body.isFocus = false
– Remove the joint when the touch ends
body.tempJoint:removeSelf()
end
end
– Stop further propagation of touch event
return true
end
– EGG
local egg_1 = display.newImage(“images/egg_main.png”)
egg_1.x = 160
egg_1.y = 100
physics.addBody( egg_1, game_object )
egg_1:addEventListener( “touch”, dragBody )
camera:insert(egg_1)
game_countdown:insert(egg_1)
– PHYSICS: ADD BODY
local game_object = { density = 1.0, friction = 0.3, bounce = 0.2 }
– Camera follows bolder automatically
local function moveCamera()
if (egg_1.y > 100 and egg_1.y < 1000) then
camera.y = -egg_1.y + 100
end
end
Runtime:addEventListener( “enterFrame”, moveCamera )
return true
end
– GAMEPLAY SCREEN
function new()
local ui = require ( “ui” )
– NEW GROUP
local gameGroup = display.newGroup()
return gameGroup
end
gameplay()[lua] [import]uid: 137824 topic_id: 24202 reply_id: 324202[/import]