Graham,
Sorry to bother again but the setPosition seems to be not acting as I expect when updating the map position.
I use it successfully in a function to set the initial map position to the player’s spawn point:
local onPlayerSpawnObject = function(object)
local layer = map:getLayer("Player")
player = display.newImage(layer.group, "player.png")
player.x = object.x
player.y = object.y
map:setPosition(player.x,player.y)
end
But it doesn’t set it as I’d expect when moving the player in a touch event. It seems to be moving to the bottom left corner of the map rather than the position I’ve just moved the player to:
local onTouch = function(event)
local pos = ugni.screenToWorldPosition(map, {x=event.x, y=event.y})
local diffx = player.x - pos.x
local diffy = player.y - pos.y
local newx = player.x
local newy = player.y
if math.abs(diffx) \> math.abs(diffy) then
if diffx \> 0 then
print("Move left")
newx = player.x - 50
else
print("Move right")
newx = player.x + 50
end
else
if diffy \> 0 then
print("Move up")
newy = player.y - 50
else
print("Move down")
newy = player.y + 50
end
end
transition.to( player, { time=500, x=newx, y=newy } )
map:setPosition(newx,newy)
end
slideToPosition seems to have the same behaviour, it’s actually the slide I want to use (so the map slides as the player moves).
Any advice appreciated,
Cheers!
Rob
[import]uid: 12431 topic_id: 4751 reply_id: 15213[/import]