Helps?
Need some helps getting my actor (is using the term actor a no-no here?) to “chase” a players finger, whilst at the same time having the camera follow the actor. Ideally I would like to have the actor rotate on an axis to the direction of the player’s finger. It is a air plane type game and you can fly in any direction.
I get the feeling I need to use a transition and some easing? Maybe?
So far I have it working but the actor is only click-and-dragable and has no axis movement. Here’s my code.
Appreciated Guys & Girls
(Forgot about the Code Exchange and I’m checking that out now but still feel free to give me a leg up, if I find anything useful I’ll post it here to help others)
Here’s my code
[lua]display.setStatusBar(display.HiddenStatusBar)
local game = display.newGroup();
game.x = 0
game.y = 0
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 0.1)
local floor = display.newRect(0, 799, 1000, 100)
game:insert( floor)
physics.addBody(floor, “static”, { bounce = 0.1 } )
local background = display.newImage(“bg.png”)
game:insert(background)
local function onTouch( event )
local player = event.target
local phase = event.phase
if “began” == phase then
local parent = player.parent
parent:insert( player )
display.getCurrentStage():setFocus(player)
player.isFocus = true
player.x0 = event.x - player.x
player.y0 = event.y - player.y
elseif player.isFocus then
if “moved” == phase then
player.x = event.x - player.x0
player.y = event.y - player.y0
elseif"ended" == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
player.isFocus = false
end
end
return true
end
player = display.newImage(“player.png”)
game:insert(player)
player.x = display.contentWidth/2
player.y = display.contentHeight/2
physics.addBody(player, {“static”})
player:addEventListener( “touch”, onTouch )
local function moveCamera()
if (player.x > 100 and player.x < 11000) then
game.x = -player.x + 300
end
if (player.y > 220 and player.y < 3000) then
game.y = -player.y + 220
end
end
Runtime:addEventListener(“enterFrame”, moveCamera)
[lua] [import]uid: 26289 topic_id: 11379 reply_id: 311379[/import]