Games [XUI2D] Limit the ScreenAABB edges not crossing the world edges

ilan

Expert
Licensed User
Longtime User

Gunther

Active Member
Licensed User
Longtime User
small part of black space but smaller then in your first screenshot

Yes, with the +2 it is gone.

Let me read the link you provided.

Greetings.
 

Gunther

Active Member
Licensed User
Longtime User
HI,

well, also on your last drawing the red frame is overlapping the screen (and tilemap) in both directions and not only the y-directions. Therefore it is not understandable by me why you used different formulas for the both directions.

Greetings.
 

ilan

Expert
Licensed User
Longtime User
HI,

well, also on your last drawing the red frame is overlapping the screen (and tilemap) in both directions and not only the y-directions. Therefore it is not understandable by me why you used different formulas for the both directions.

Greetings.

sorry i have not understood what you mean in your last post. the red frames are drawn by me only to show you the frame of youtube player. it is not show in my phone.
 

Gunther

Active Member
Licensed User
Longtime User
hm,

may it has also to do with the ratio in the Designer. My Ratio is 1.07, but when I used the unchanged I am getting a non filled screen:
normal Ratio.PNG


While changing the Designer Script by swapping the orientation:
RatioDesigner.PNG


I am getting a normal full screen but as you know the settings have influence to the given setup:

B4X:
Dim WorldWidth As Float = WorldHeight * 1.3333

Therefore I have the feeling I am running in the forest with no way out.
 

Gunther

Active Member
Licensed User
Longtime User
Dears,

I don't care about the color to be seen outside the tilemap. It should simply not be seen at all. Means the screen should never be outside the tilemap.

Greetings
 

Gunther

Active Member
Licensed User
Longtime User

Gunther

Active Member
Licensed User
Longtime User
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Change the code in Mario class to:
B4X:
If bw.Body.WorldCenter.X > x2.ScreenAABB.Center.X Then
       'update the screen center
       Dim WorldX As Float = Min(bw.Body.WorldCenter.X, bw.mGame.TileMap.MapAABB.TopRight.X - x2.ScreenAABB.Width / 2)
       If WorldX > x2.ScreenAABB.Center.X Then
           x2.UpdateWorldCenter(x2.CreateVec2(WorldX, x2.ScreenAABB.Center.Y))
           bw.mGame.WorldCenterUpdated(GS)
       End If
   End If
 

Gunther

Active Member
Licensed User
Longtime User
Thanks this. And for both axis at the same time? Maens it should not only the x-direction limited also the y-direction and may be both, if the character is near to a corner.
 
Last edited:

Gunther

Active Member
Licensed User
Longtime User
Dear Erel,

your code works as expected only for the right end of the tilemap as it is used in your Mario example.
unfortunately not for the left edge and not for both dimentions together when adapted to the y-direction.

My approach was this. At least it works for both sides of x-Direction but not for the y-direction and for sure not for both togehter:
B4X:
    If (x2.ScreenAABB.BottomLeft.X >= 0 And bw.Body.WorldCenter.X < x2.ScreenAABB.Width/2) Or _
          (x2.ScreenAABB.TopRight.X >= Main.WorldEdges.Right And bw.Body.WorldCenter.X > Main.WorldEdges.Right-x2.ScreenAABB.Width /2)  Then
        x2.UpdateWorldCenter(x2.CreateVec2(x2.ScreenAABB.Center.X,  bw.Body.WorldCenter.y))
    Else
        x2.UpdateWorldCenter(x2.CreateVec2(bw.Body.WorldCenter.X, bw.Body.WorldCenter.y))
    End If
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
your code works as expected only for the right end of the tilemap as it is used in your Mario example
That's true. It was added to the Mario example where the screen only moves to the right.
There is nothing special about this code. You need to understand it and you will then be able to limit the screen movement in any way you like.

I've updated the X2Tiles example and it now limits the map movement to the visible map. The relevant code is:
B4X:
Sub ClipScreenCenterToMapArea (v As B2Vec2) As B2Vec2
   Dim ScreenHalfWidth As Float = X2.ScreenAABB.Width / 2
   Dim ScreenHalfHeight As Float = X2.ScreenAABB.Height / 2
   v.X = Max(ScreenHalfWidth, Min(TileMap.MapAABB.Width - ScreenHalfWidth, v.X))
   v.Y = Max(ScreenHalfHeight, Min(TileMap.MapAABB.Height - ScreenHalfHeight, v.Y))
   Return v
End Sub
 
Top