Strange behaviour with button-triggered slideToPosition function

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]

What behaviour are you getting? [import]uid: 119420 topic_id: 22991 reply_id: 92045[/import]

The camera moves (in all 3 instances) to positions way off the map, somewhere to the top left of it. It’s as if the coordinate-system is off by several positions.
Could it be because I’ve set the orientation to landscapeLeft in the build.settings? [import]uid: 129287 topic_id: 22991 reply_id: 92049[/import]

Ah yea there is a possibility that is connected. Are you able to do quick test without that and then also if possible make a really small demo showing the issue that I can take a look at? [import]uid: 119420 topic_id: 22991 reply_id: 92595[/import]

I did try it without the build.settings but I still get an error. Another thing I’ve noticed is that the coordinate system is always orientated around the phone being in the normal portrait position, at least when not using physics. A great addition would be a command which sets the orientation of the coordinate-system, something like setOrientation = landscapeLeft. This would really help programming apps with a forced orientation as the x-axis would still be left right with the positives to the right and the same for the y-axis. It could also be used with “dynamic” orientation as one could check for the orientation of the phone and then just setOrientation to the current.
Anyway, I’m sending you a small demo of the slideTo problem.

Thanks. [import]uid: 129287 topic_id: 22991 reply_id: 92608[/import]

Issue resolved, bug in the slideObjectToPosition function in lime-utils.lua, fix will be included in 3.5 and I have sent you an email :slight_smile: [import]uid: 119420 topic_id: 22991 reply_id: 93941[/import]

Thanks for your email and for solving the issue as this caused me some headache. Couldn’t see where I went wrong… My code now works just as intended!

And by the way, I’m really beginning to appreciate a Lime with my Corona! [import]uid: 129287 topic_id: 22991 reply_id: 94158[/import]

Awesome! Glad to hear it :slight_smile: [import]uid: 119420 topic_id: 22991 reply_id: 94556[/import]

I’m sorry to say, but another issue has surfaced. Actually it’s a couple of things.

The first glitch (no pun intended) happens when sliding from one position to another and then setting the focus to a sprite at that position. (I’ve got several sprites that the player can control, and I’m moving the camera between them). This works just fine most of the time, but in some cases (unknown when) the setFocus function won’t lock onto the sprite and the camera stops following it.

The second problem might be my lack of understanding and not a bug, but there seems to be a misalignment between the worldposition of the sprites and the map when using setFocus. I have a sprite/player-character who has a gun, so I figured I should fire the bullet from my player.x, player.y position. However, this position doesn’t relate to where the sprite is on the map. It might have to do with the map moving 32 pixels (1 grid position) simultaniously with the sprite. So when moving the sprite when the camera is focused on it, the sprite moves one tile and the camra following it sort of nulls out the sprite-movement. This again seems to somehow interfer with the x/y position of the sprite. Strangely enough it works just fine when I’m moving the camera using slideToPosition to my player.x, player.y position. In this case the x,y position seems to be right.

So, could I once again bother you to take a look at it? [import]uid: 129287 topic_id: 22991 reply_id: 96993[/import]

I believe I have resolved this issue with you by email now? [import]uid: 119420 topic_id: 22991 reply_id: 97789[/import]

All issues have now been resolved.

Many thanks. [import]uid: 129287 topic_id: 22991 reply_id: 97820[/import]

Great! [import]uid: 119420 topic_id: 22991 reply_id: 97934[/import]