For my understanding X direction and y-direction are independent dimensions, e.g. both directions should follow the same mathematics.
Therefore I didn't get why your x-direction is coded diffrently compared to the y-direction (minY and maxY)!?
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.
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.
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.
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.
Correct, the screen should stay always in the tilesmap while the character is able to reach the edges when the screen is at the edges but the screen shall follow the character when the edges of the map are not reached by the screen.
As we have it here in the Video partly for x-direction.:
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
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.
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
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