How to keep HUD in same place when camera rotates

I am working on a running platform game and I would like to add some rotating scene and I have some problem: I would like to apply a score and buttons controls, but when rotate the camera I can't maintain the initial position.
I fixed the angle using: self.rotation = -camera.rotation but it can't help me to maintain the initial position.
I tried to use:
self.position.x = game.sceneX-magnitude( self.offsetX , self.offsetY )*sin(( self.Rotation )-atan( self.offsetX / self.offsetY ))
self.position.y = game.sceneY+magnitude( self.offsetX , self.offsetY )*cos(( self.Rotation )-atan( self.offsetX / self.offsetY ))
but It doesn't solve the problem.

Could somebody help me?

Comments

  • CodeMonsterCodeMonster ACT, AustraliaMember Posts: 1,078
    this might be wrong but maybe try constraining your HUD buttons to a certain x and y position? maybe.
    im not sure sorry but maybe you could try this, no harm in giving it a go
  • firedream79firedream79 Member Posts: 8
    camera.rotate rotates all the elements on the screen using its center as pivot, so if you use a centered image you solve the problem, but you can't if you use another at the top-left of the screen.
  • firedream79firedream79 Member Posts: 8
    I noticed that many other users had the same problems but I didn't find any solution.
  • firedream79firedream79 Member Posts: 8
    any solutions?
  • CodeMonsterCodeMonster ACT, AustraliaMember Posts: 1,078
    im not sure how you can do this but you can somehow work out which way the screen has rotated and just constrain the x and y co-ordinates to be the bottom of the screen depending on which way the screen rotates, heres an example

    in your HUD button it is constrained y 100 and lets say the screen rotates 100 degrees to the right then you constrain it to y 200. you can probably do this after using attributes and more, but i never use screen rotate so its hard for me, maybe @Socks knows?
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    If you track its orientation it should be easy to update the HUD based on the current orientation.
  • firedream79firedream79 Member Posts: 8
    I solved for orientation using -camera.rotation, my problem is that the actor moves on screen...
  • firedream79firedream79 Member Posts: 8
    I interpolated camera.rotate from 0 to 10 in 1s.
    I constrained my actor defining start (x,y) and end position.
    The problem is that even if I have been very carefull I can't avoid micromovements...
    For this reason I am looking for some better solution...
  • firedream79firedream79 Member Posts: 8
    I hope that somebody solved the problem and can help me...is there some solutions to make some layers uninfluenced by camera effects?
  • CodeMonsterCodeMonster ACT, AustraliaMember Posts: 1,078
    i wish i could help, but sorry i dont know the answer...
  • rdlew2008rdlew2008 Member, PRO Posts: 85
    edited November 2013
    I am not sure if this is what you need but....

    this will keep it from a certain distance away from your main character (the 235)

    at a certain angle (the 142)
    i use 142 to keep HUD in upper left corner and 33 for upper left corner

    both have to be the same numbers


    this needs to be on a scrolable scene.

    constrain attribute
    -consttrain: self.rotation to scene.camera.rotation

    constrain attribute
    -constrain : self.position.x to (scene.hero.hero.position.x)+235*cos(scene.camera.rotation)+142


    constrain attribute
    -constrain : self.position.y to (scene.hero.hero.position.y)+235*cos(scene.camera.rotation)+142
  • firedream79firedream79 Member Posts: 8
    nothing...I am trying to try with your advice, I put to actors in the scene:
    ACTOR 1 and ACTOR 2 (235,235).
    I rotate camera wtih an angle 235, but ACTOR 2 doesn't keep the start position...

    actor2.x = scene.Background.Actor 1.Position.X +235*cos( scene.Camera.Rotation )+142
    actor2.y = scene.Background.Actor 1.Position.Y +235*cos( scene.Camera.Rotation )+142

    maybe I am doing some mistakes?

    I am trying to keep fixed the score in the upper left corner when the camera rotate +10, but it seems impossible on GS.
    Could somebody help me?
  • UtopianGamesUtopianGames Member Posts: 5,692
    edited December 2013
    Would it be possible to use a background image with the HUD controls on it and constrain its rotation to - scene.camera.rotation like in our template below.



    http://www.deepblueapps.com/helicopter-hud-template/

    Another way would be like you mentioned using cos and sin like our rolling bones (playable link below).

    Quick piece of advice if your having a pause button in the top right for e.g. and your going the cos sin route you will need a fake pause button (alpha 0 or graphics off) on a layer with scrollable unchecked for it to register a touch.



    http://www.deepblueapps.com/rolling-bones/

    Darren.

  • firedream79firedream79 Member Posts: 8
    for now I am adjusting manually the positions of x,y of ACTOR2 after the camera rotation of 10 degrees, it gives me bad micromovements, but I suppose that it isn't normal all this. I don't understand why GS don't give the possibility to introduce LAYER external to camera rotation, zooming and so on.
    I
  • RubiWorksRubiWorks Member Posts: 130
    I have the same problem dear @firedream79 GS Team would be a better formule to correct this. An behaviors because is very boring trying with cos and sin if you want to sync a button in a game that rotate the camera.
Sign In or Register to comment.