透视虚拟相机库问题Corona SDK

时间:2014-06-17 00:54:43

标签: lua camera corona perspective

大家好我正在开发一个我将使用透视图库的应用程序。我已经导入了库并且已经编写了正确的代码,但无济于事我的相机无法正常工作。我试图让相机跟随你用按钮移动的主角。我加了他和背景以及一棵树"到相机并把他作为焦点,但它仍然不会跟随他。这是我的代码,请告诉我这里做错了什么以及如何修复它。

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local perspective = require( "perspective" )
local camera = perspective.createView()
local physics = require( "physics" )
--physics.setDrawMode( "hybrid" )



local function start( event )
if( event.phase == "ended" ) then

end
end 

local bg
local floor
local leftwall
local rightwall
local player  
local button1
local button2
local pausebtn
local tree

local function b1( event )
if( event.phase == "ended" ) then
player:applyLinearImpulse( -.01, -.1 )
end
end

local function b2( event )
if( event.phase == "ended" ) then
player:applyLinearImpulse( .01, -.1 )
end
end

local function playerCollision( event )
if( event.phase == "began" ) then
storyboard.gotoScene( "gameover" )
end
end 

local function pause( event )
if( event.phase == "ended" ) then
storyboard.showOverlay( "pause" )
physics.pause()
end
end

function scene:createScene( event )
local group = self.view
    physics.start()



    bg = display.newImage( "bg.png", display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight )
camera:add(bg, 3, false)
    player = display.newImage( "player.png", display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight )
    player.collision = playerCollision  
camera:add(player, 1, true)
    tree = display.newImage( "tree.png", 200, 200)
camera:add(tree, 2, false)

    floor = display.newRect( 285, 375, 570, 1 )
    button1 = display.newImage( "button1.png", 50, 275 )
    button2 = display.newImage( "button2.png", 515, 275 )

    leftwall = display.newRect( 0, -1000, 1, 5000 )
    rightwall = display.newRect( 570, 300, 1, 5000 )

    pausebtn = display.newImage( "pausebtn.png", 540, 30 )

    -- Physics
    physics.addBody( player )

    physics.addBody( floor ) 
    floor.bodyType = "static"

    physics.addBody( rightwall )
    rightwall.bodyType = "static"

    physics.addBody( leftwall )
    leftwall.bodyType = "static"



    group:insert(bg)
    group:insert(player)
    group:insert(floor)
    group:insert(button1)
    group:insert(button2)
    group:insert(rightwall)
    group:insert(leftwall)
    group:insert(pausebtn) 
    group:insert(tree)

end

function scene:enterScene( event )
print( "game" )
button1:addEventListener( "touch", b1 )
button2:addEventListener( "touch", b2 )
player:addEventListener( "collision", playerCollision )
pausebtn:addEventListener( "touch", pause )



end

function scene:exitScene()

player = nil
camera:cancel()


end

function scene:destroyScene( event )



end 

scene:addEventListener( "createScene", scene )

scene:addEventListener( "enterScene", scene )

scene:addEventListener( "exitScene", scene )

scene:addEventListener( "destroyScene", scene )

return scene

1 个答案:

答案 0 :(得分:0)

看起来你错过了对camera:track()的调用(可能应该放在enterScene处理程序中)。您可能还需要camera:setBounds(false)

如果这仍然无法解决问题,请从帖子中删除所有不需要的代码,以便复制问题。如果你可以把它归结为我可以运行的一个小例子,我可以尝试发布更新。