Rotation Pivot Point

Is there a way to set the pivot point in the map:setRotation(), the map:rotate(), the tileLayer:rotate() or the tileLayer:setRotation() functions? If not, is it a planned addition to an upcoming release? [import]uid: 129287 topic_id: 23167 reply_id: 323167[/import]

You could try setting the xReference and yReference values of the map before rotating but I can’t guarantee this will give the desired results, something like this:

  
local visual = map:getVisual()  
  
local onTap = function( event )  
  
 local worldPosition = lime.utils.screenToWorldPosition( map, event )  
  
 visual.xReference = worldPosition.x  
 visual.yReference = worldPosition.y  
  
 map:setRotation( 45 )  
  
end  
  
Runtime:addEventListener( "tap", onTap )  
  

Again, I am not sure if this will work but I figure it is worth a try :slight_smile: [import]uid: 119420 topic_id: 23167 reply_id: 93949[/import]

Thanks for your suggestion but unfortunately it didn’t work. It only sets the viewpoint, not the pivot point. The pivot point is still in the top left corner (0,0) of the map or the layer. Any chance of this being implemented in an upcoming release? [import]uid: 129287 topic_id: 23167 reply_id: 94160[/import]

Ah right, darn it. I am not sure of how quickly I could get something like this implemented.

Anyone know how easy this sort of thing would be in Corona? [import]uid: 119420 topic_id: 23167 reply_id: 94558[/import]

I figured this one out, or at least partially.

It’ll work by adding the following line above the self.group.rotation variable in the TileLayer:rotate(angle) and TileLayer:setRotation(angle) function in lime.tileLayer.lua:

self.group:setReferencePoint( display.CenterReferencePoint )

Any of the following parameters can be used:
display.CenterReferencePoint
display.TopLeftReferencePoint
display.TopCenterReferencePoint
display.TopRightReferencePoint
display.CenterRightReferencePoint
display.BottomRightReferencePoint
display.BottomCenterReferencePoint
display.BottomLeftReferencePoint
display.CenterLeftReferencePoint

Reference:
http://developer.anscamobile.com/reference/index/objectsetreferencepoint

Or it could easily be made into a function called setPivotPoint() which would accept the following variables: TopLeft, TopCenter, TopRight, CenterLeft, Center, CenterRight, BottomLeft, BottomCenter and BottomRight.

It wasn’t exactly what I was aiming for, as I was planning to have the pivot point centered around a sprite/player-character seen from a top-down view. Then when moving right or left, instead of turning the sprite I would rotate the map beneath it. But at this stage it seems impossible to place the pivot-point more accurately. [import]uid: 129287 topic_id: 23167 reply_id: 97323[/import]

I could be entirely wrong about how setReferencePoint() works, but couldn’t you actually do what you’re suggesting, and feed it the player’s reference point? The documentation suggests its limited to those parameters, but since you have to add “display” I thought you could feed it the RP of other objects…

(I guess I’m really just suggesting a code idea here, not a solution)

[import]uid: 41884 topic_id: 23167 reply_id: 97402[/import]

@Dr.Mabuse - if a setPivotPoint() function as you describe will be useful I will happily put it in. Will naturally need to test that it doesn’t affect anything else weirdly but that’s what a beta is for :slight_smile:

@ richard9 - I’m also not entirely sure if that would work or not. I haven’t had much experience with reference points myself.
[import]uid: 119420 topic_id: 23167 reply_id: 97790[/import]

@richard9: Your idea might be something to look into. I’m not sure if it’ll work but it could be worth a try. I haven’t gotten to this yet as I’m busy with other projects, and this was just an idea I had for a future project. It probably requires some deeper understanding of the lime-code than where I’m at at the moment and I haven’t really been studying the lime-source particularly closely. I might be picking up on this at a later stage.

@Glitch Games: As long as there is a function for rotating the layers, I can’t see why giving the user more control over it wouldn’t be useful. More control can never be a disadvantage. You should naturally give this a thoroughly check as I haven’t really done anything with this since it wasn’t as versatile as I wanted it to be. In case you decide to implement it, you should also check if it works with several layers, object layers, sprites and so on. [import]uid: 129287 topic_id: 23167 reply_id: 97994[/import]

Yup, more control is definitely a good thing so I hope to find some time to get it in and test properly soon. [import]uid: 119420 topic_id: 23167 reply_id: 99891[/import]