Dynamically Placed Actors In Large Scene With Camera Movement

Hi all,

I have one actor for all my UI elements. I set the image for each instance with a self text attribute. That part is happy. I was setting their positions with a rule based on the work of @colander exploring aspect ratios. That part was also happy.

The unhappiness came when I realized I needed different math because I use one big scene and a locked camera that jumps around to the various 'screens' making the actors in those other screens not get placed correctly.

I essentially need better math to place these actors based on my scene size/placement within the scene/aspect ratio/something something. I'm just having trouble with the function. Anyone want to do some high level math for me?

Scene size is 1,280w X 1,136h
I have 8 'screens'. Each one is 320w X 568h (so 4 across top and 4 across bottom)
The game starts in the bottom left screen. I'm using Overscan.

This is a picture of the rule I'm using to place my UI actors.

thanks very much

Comments

  • RowdyPantsRowdyPants Member Posts: 465

    I figured it out!

    I have since changed my layout but for the benefit of anyone interested here's how.

    In actor containing the dynamic placement rule, I created 2 self attributes, ScreenPositionY (integer) and ScreenPositionX (integer). Then I drop them into the rule, adding and subtracting themselves when needed.

    [IF] Rule: Dynamic Placement
    When 320/568 <= game.Screen.Size.Width/game.Screen.Size.Height
    (When My Camera's Aspect Ratio is < or = Current Device's Aspect Ratio)

    [THEN] Action: Change This Actor's Y Coordinate
    Change self.Position.Y to 568/2+( self.Position.Y - self.ScreenPositionY )-568/2)*( game.Screen.Size.Height /( game.Screen.Size.Width *(568/320)))+ self.ScreenPositionY

    [ELSE] Action: Change This Actor's X Coordinate
    Change self.Position.X to 320/2+(( self.Position.X - self.ScreenPositionX )-320/2)*( game.Screen.Size.Width /( game.Screen.Size.Height *(320/568)))+ self.ScreenPositionX

    Then it's just a matter of going into each instance of this UI actor on each 'screen' and setting their self.ScreenPositionX and self.ScreenPositionY to the correct locations. (the top left screen UI actor instances would need to be ScrnPosY = 568 and ScrnPosX = 0 to move down one full screen but not move left or right any)

    I basically pretend the actor is on the happy starting screen (bottom left one), calculate its placement within that screen according to the device's aspect ratio, then move it back up to its original screen.

    This one racked my brain for weeks. I can finally sleep easy. Cheers

Sign In or Register to comment.