Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problems with rotating map in Dusk
Started by allankstevens Sep 21 2016 12:39 PM

5 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

allankstevens

[GLOBAL: userInfoPane.html]
allankstevens
  • Observer

  • 15 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

Alex@Panc

[GLOBAL: userInfoPane.html]
Alex@Panc
  • Corona Geek

  • 1,729 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

allankstevens

[GLOBAL: userInfoPane.html]
allankstevens
  • Observer

  • 15 posts
  • Corona SDK

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.

 



[TOPIC: post.html]
#4

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

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



[TOPIC: post.html]
#5

allankstevens

[GLOBAL: userInfoPane.html]
allankstevens
  • Observer

  • 15 posts
  • Corona SDK

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!



[TOPIC: post.html]
#6

allankstevens

[GLOBAL: userInfoPane.html]
allankstevens
  • Observer

  • 15 posts
  • Corona SDK

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/




[topic_controls]
[/topic_controls]