Ok, I’ve had a chance to play around with Perspective a bit. First off, great stuff … thanks Caleb!
Below is a test case I made (plug n play code):
[lua]display.setStatusBar( display.HiddenStatusBar )
local physics = require “physics”
physics.start()
physics.setDrawMode( “hybrid” )
local perspective=require(“perspective”)
local camera=perspective.createView()
local ground = display.newRect( 0, 300, 480, 50 )
ground:setFillColor( 0, 255, 0 )
camera:add(ground, 3, false)
physics.addBody(ground, “static”, { density=1.0, friction=0.4, bounce=0})
local hero = display.newRect( 150, 300, 15, 50 )
hero:setFillColor( 255, 0, 0 )
camera:add(hero, 1, false)
physics.addBody(hero, “dynamic”, { density=1.0, friction=0.4, bounce=0})
hero.isFixedRotation = true
local crate = display.newRect( 200, 300, 15, 15 )
crate:setFillColor( 0, 0, 255 )
camera:add(crate, 2, false)
physics.addBody(crate, “dynamic”, { density=1.0, friction=0.4, bounce=0.3})
local forwardBtnPressed = false
local backBtnPressed = false
local function moveCharacter(event)
if forwardBtnPressed then
hero.x = hero.x + 3
elseif backBtnPressed then
hero.x = hero.x - 3
end
end
function forwardBtnPressed(event)
forwardBtnPresssed = false
backBtnPressed = false
if event.phase == “began” then
forwardBtnPressed = true
Runtime:addEventListener( “enterFrame”, moveCharacter )
elseif event.phase == “ended” then
Runtime:removeEventListener( “enterFrame”, moveCharacter )
forwardBtnPressed = false
end
print(hero.x)
return true
end
function backBtnPressed(event)
forwardBtnPresssed = false
backBtnPressed = false
if event.phase == “began” then
backBtnPressed = true
Runtime:addEventListener( “enterFrame”, moveCharacter )
elseif event.phase == “ended” then
Runtime:removeEventListener( “enterFrame”, moveCharacter )
backBtnPressed = false
end
return true
end
local forwardBtn = display.newRect(display.contentWidth/2,display.contentHeight/2,display.contentWidth/2,display.contentHeight)
forwardBtn:setFillColor(0, 0)
local backBtn = display.newRect(0,display.contentHeight/2,display.contentWidth/2,display.contentHeight)
backBtn:setFillColor(0, 0)
camera:setFocus(hero)
camera:track()
camera.damping=30
camera:setBounds(0, display.contentWidth*4, 0, display.contentHeight)
forwardBtn:addEventListener( “touch”, forwardBtnPressed )
backBtn:addEventListener(“touch”, backBtnPressed )[/lua]
You can touch the left or right side of the screen to move the “hero” (red block) around.
My issue is that you can see when the red block moves into the crate, they interfere or overlap each other before being pushed apart. I know this is happening because of how I have the code setup to move the red block (x = x+3 on enterFrame)… so when the red block is next to the crate, it is instantaneously being overlapped by 3 pixels on the crate … then the physics engine detects the collision and pushes them apart.
This becomes less apparent the smaller you increment the chance (x = x+.5 for example), but this makes the character movement unacceptably slow.
I’m wondering if either of you know of a better way that I can have the character move (during a continuous touch event) that doesn’t cause this problem? [import]uid: 146966 topic_id: 34642 reply_id: 138001[/import]