Rotating the camera while maintaining a HUD

patrickbeardmorepatrickbeardmore Member Posts: 11
edited July 2012 in Working with GS (Mac)
My game involves a scene where the viewer is in a helicopter, looking down, while the scene rotates and moves below. I am trying to use interpolate to rotate the camera, which is working well, but I cannot work out how to make the HUD (head up display) overlay layer stay still.

Does anyone have any tested solutions. An example file would be ideal. Regards, Patrick

Best Answer

  • UtopianGamesUtopianGames Posts: 5,692
    Accepted Answer
    When you rotate the camera it doesn't change the positions of the HUD buttons like rotate left rotate right etc etc even though it looks like it does so there's no need to move them at all.

    Here's a quick video of an older project with rotation of the camera and a stationary HUD.



    Hope it helps.

    Darren.

Answers

  • SparkyidrSparkyidr Member Posts: 2,033
    you can counteract the rotation by constraining an actors rotation to
    "-(scene.camera.rotation)"

    But that's only half of the battle

    keeping it in place is the hard part, that I have still not figured out a way of doing.
  • patrickbeardmorepatrickbeardmore Member Posts: 11
    Many thanks. Do you have any suggestions of an approach for keeping the positions constant? Can anything be done with scrollable layers?
  • BarrytheBraveBarrytheBrave Member Posts: 134
    edited July 2012
    This is what I am doing for my current game:

    I made one single HUD graphic which was transparent, the size of my entire screen and this had all of the HUD elements drawn on it. Then by using contrain to -scene.camera rotation, the whole HUD graphic rotates from the centre, keeping everything in place as it rotates.

    Obviously you now can't use this graphic to detect touches, as the whole screen would register a touch, so I added some invisible buttons above the HUD graphic to detect touches.

    I'm lucky because in my game the camera only rotates when the left or right button is pressed, so I don't need to constrain the invisible buttons to keep them in place, I simply have a rule saying that during camera rotation the buttons can't be pressed, and once camera rotation is complete I simply move the invisible buttons to a pre set coordinate that I know is in line with my rotated HUD graphic.

    Depending on the rotation in your game this might not be a complete solution for you but it might help!
  • gurechangurechan Member, PRO Posts: 211
    @ooi thanks for this, I've been trying to find a solution so this exact thing. Works great for my needs.
  • BarrytheBraveBarrytheBrave Member Posts: 134
    @gurechan No probs, glad I could help!
  • developer6810developer6810 Member Posts: 139
    @gurechan

    If you wanted to do something about layers, you could go to your scene, click on scene attributes, go to layers and create a new layer. Put all the buttons and things you want on the HUD in the new layer and unclick scrollable. This will make the HUD always stay in the same spot.
  • SparkyidrSparkyidr Member Posts: 2,033
    @gurechan

    If you wanted to do something about layers, you could go to your scene, click on scene attributes, go to layers and create a new layer. Put all the buttons and things you want on the HUD in the new layer and unclick scrollable. This will make the HUD always stay in the same spot.
    not when rotating the camera it wont.
  • patrickbeardmorepatrickbeardmore Member Posts: 11
    I will attempt to use ooi's approach. Thanks for your help.

    In the long-term, it would be handy to have a check box next to "scrollable" for "rotatable" in the layers panel, to avoid this problem.
  • patrickbeardmorepatrickbeardmore Member Posts: 11
    @ooi
    ...once camera rotation is complete I simply move the invisible buttons to a pre set coordinate that I know is in line with my rotated HUD graphic.
    Would you be prepared to explain exactly how you do this last step? Is there a calculation involved and how do you get the positioning right?
  • patrickbeardmorepatrickbeardmore Member Posts: 11
    This is extremely helpful! Many thanks.

    If I understand it, the image and the button registration becomes misaligned, but this can be used to make the HUD work anyway.
  • BarrytheBraveBarrytheBrave Member Posts: 134
    @UtopianGames great explanation!

    @patrickbeardmore Yeah there seems to be a weird situation going on with the buttons - even though they graphically appear to move, their touch detection still seems to stay in the original location. It must be a GS bug that's actually working in our favour for this situation.

    To clarify my earlier explanation - in my particular game the screen rotates in four directions - every time you press left or right you rotate by 90 degrees. As well as this the hud position never moves from 0,0, it only rotates. Because of this I worked out (with some manual placement and testing) that when rotation=90 degrees button1 must be at a certain position, so I had a rule saying when camera.rotation=90 set button position to (relevant coordinates), then if camera.rotation=180 set button.position to (relevant coordinates), etc. Because the button isn't visible you never see it moving to it's new position.

    However seeing as the buttons seem to always detect touch at the same place I might not actually need these rules anymore!
Sign In or Register to comment.