Problems with rotating map in Dusk

Hi

I’m trying to create a kind of maze game with Dusk, but have been stuck for days trying to get the map to pivot from the centre of the camera.

I have a map that is larger than the screen (50x50 tiles).  The player starts in the middle and when you turn, i’m trying to get the map to rotate as well, so the player is always upright.  But this is where I have issues, it seems to always pivot from the top left corner of the camera.  I have set the anchorX, anchorY to 0.5,0.5 and set the anchorGroup to true.

I’m hoping its me doing something silly, i’m new to Corona. Here are the bits of my code that I hope can help. Any suggestions would be really appreciated.

-------------------------------------------------------------------------------- -- Load Map -------------------------------------------------------------------------------- map = dusk.buildMap("maps/world" .. levelNum .. ".json") map.anchorX, map.anchorY = 0.5, 0.5 map.anchorGroup=true sceneGroup:insert( map ) -------------------------------------------------------------------------------- -- Create Player -------------------------------------------------------------------------------- hero = newHero( { x=map.data.width/2, y=map.data.height/2 } ) -- centred to map map.layer["tiles\_static"]:insert(hero) map.positionCamera(hero.x , hero.y) -- position camera on hero --map.setCameraFocus(hero) --map.setTrackingLevel(1) -------------------------------------------------------------------------------- -- Rotate map 360 degrees to test -------------------------------------------------------------------------------- transition.to(map, { time = 6000, rotation = 360 } )

Thanks for looking.

Assuming you don’t have any GUI objects inserted into sceneGroup, you could always rotate that group, and rotate your hero object relative to that.

I have removed the GUI objects for testing, and set the rotation to the sceneGroup instead.  Also setting the anchor points to 0.5.  But it still rotates from the top left content area.  See youtube video.    

Should I be able to rotate the scene from the centre? am i trying the impossible? thanks.

[media]https://www.youtube.com/watch?v=cBTODJL8OmY&feature=youtu.be[/media]

You can rotate the map directly, just make sure (as always) to call map:updateView() afterwards. You’ll also need to set the map’s camera focus to something to let Dusk know what you want to rotate around. If you’re not tracking your player, you can make a hidden display object as the camera focus.

map.rotation = 90 map:updateView()
  • Caleb

Hi Caleb,

Thanks for the idea of using a hidden display object for camera focus.  Nice idea, but was still rotating from the top left corner as show in my video.  I have managed to get it to work now.  What I did was offset the maps x,y coordinates to +128 (half the content area).  I’m then setting the positionCamera + 128.  It now pivots from the middle.

Thanks again for the help (and Alex@Panc)

btw, Caleb, your tile engine is fantastic!

Caleb - game is now in beta.  If you have time please check it out.  I have credited you (and Corona SDK)  on the credits page (heart icon) within the game.

https://forums.coronalabs.com/topic/66333-lost-little-spaceman-game-using-dusk/

Assuming you don’t have any GUI objects inserted into sceneGroup, you could always rotate that group, and rotate your hero object relative to that.

I have removed the GUI objects for testing, and set the rotation to the sceneGroup instead.  Also setting the anchor points to 0.5.  But it still rotates from the top left content area.  See youtube video.    

Should I be able to rotate the scene from the centre? am i trying the impossible? thanks.

[media]https://www.youtube.com/watch?v=cBTODJL8OmY&feature=youtu.be[/media]

You can rotate the map directly, just make sure (as always) to call map:updateView() afterwards. You’ll also need to set the map’s camera focus to something to let Dusk know what you want to rotate around. If you’re not tracking your player, you can make a hidden display object as the camera focus.

map.rotation = 90 map:updateView()
  • Caleb

Hi Caleb,

Thanks for the idea of using a hidden display object for camera focus.  Nice idea, but was still rotating from the top left corner as show in my video.  I have managed to get it to work now.  What I did was offset the maps x,y coordinates to +128 (half the content area).  I’m then setting the positionCamera + 128.  It now pivots from the middle.

Thanks again for the help (and Alex@Panc)

btw, Caleb, your tile engine is fantastic!

Caleb - game is now in beta.  If you have time please check it out.  I have credited you (and Corona SDK)  on the credits page (heart icon) within the game.

https://forums.coronalabs.com/topic/66333-lost-little-spaceman-game-using-dusk/