I’m trying to make the camera move to different positions on the map by pressing different buttons, but my code seems to generate a strange behaviour in the slideToPosition function. Am I doing something wrong?
display.setStatusBar( display.HiddenStatusBar )
local back = display.newRect(0, 0, display.contentWidth, display.contentHeight)
back:setFillColor(165, 210, 255)
local lime = require("lime")
local ui = require("ui")
local map = lime.loadMap("Slide.tmx")
map:disableScreenClamping()
local visual = lime.createVisual(map)
local MyLayer = map:getTileLayer("Tile Layer 1")
-- Initialize
-- This is where the tiles named A, B and C are situated on the map
local gridPositionA = { column = 2, row = 2 }
local gridPositionB = { column = 15, row = 7 }
local gridPositionC = { column = 8, row = 16 }
-- gridpos. are translated to worldpos. in preperation for the slideToPosition function
local positionG = lime.utils.gridToWorldPosition( map, gridPositionA )
local positionR = lime.utils.gridToWorldPosition( map, gridPositionB )
local positionB = lime.utils.gridToWorldPosition( map, gridPositionC )
-- Main update function
local onUpdate = function( event )
map:update( event )
end
Runtime:addEventListener( "enterFrame", onUpdate )
-- Button Functions
local onComplete = function()
print( "Move Complete" )
end
local onGreenButton = function( event )
map:slideToPosition(positionG.x, positionG.y, 600, onComplete)
end
local onRedButton = function( event )
map:slideToPosition(positionR.x, positionR.y, 600, onComplete)
end
local onBlueButton = function( event )
map:slideToPosition(positionB.x, positionB.y, 600, onComplete)
end
-- Define Buttons
local buttonGreen = ui.newButton{
default = "ButtonG.png",
over = "ButtonG.png",
onPress = onGreenButton
}
buttonGreen.x = display.contentWidth - buttonGreen.width \* 6
buttonGreen.y = display.contentHeight - buttonGreen.height
local buttonRed = ui.newButton{
default = "ButtonR.png",
over = "ButtonR.png",
onPress = onRedButton
}
buttonRed.x = display.contentWidth - buttonRed.width \* 5
buttonRed.y = display.contentHeight - buttonRed.height
local buttonBlue = ui.newButton{
default = "ButtonB.png",
over = "ButtonB.png",
onPress = onBlueButton
}
buttonBlue.x = display.contentWidth - buttonBlue.width \* 4
buttonBlue.y = display.contentHeight - buttonBlue.height
Any ideas? Thanks. [import]uid: 129287 topic_id: 22991 reply_id: 322991[/import]