Hi,
I am wonder if there is an easy way to limit the screen to display regions outside of the tiles layers?
Greetings, Gunther
' ####################################################
Dim WorldFixX As Float, WorldFixY As Float
' horizontal
If bw.X2.ScreenAABB.TopRight.X - bw.Body.WorldCenter.X < MIN_DISTANCE_TO_SIDES Then
'
WorldFixX = MIN_DISTANCE_TO_SIDES - (bw.X2.ScreenAABB.TopRight.X - bw.Body.WorldCenter.X)
Else If bw.Body.WorldCenter.X - bw.X2.ScreenAABB.BottomLeft.X < MIN_DISTANCE_TO_SIDES Then
'
WorldFixX = -(MIN_DISTANCE_TO_SIDES - (bw.Body.WorldCenter.X - bw.X2.ScreenAABB.BottomLeft.X))
End If
' vertical
If bw.X2.ScreenAABB.TopRight.Y - bw.Body.WorldCenter.Y < MIN_DISTANCE_TO_SIDES Then
'
WorldFixY = MIN_DISTANCE_TO_SIDES - (bw.X2.ScreenAABB.TopRight.Y - bw.Body.WorldCenter.Y)
Else If bw.Body.WorldCenter.Y - bw.X2.ScreenAABB.BottomLeft.Y < MIN_DISTANCE_TO_SIDES Then
'
WorldFixY = -(MIN_DISTANCE_TO_SIDES - (bw.Body.WorldCenter.Y - bw.X2.ScreenAABB.BottomLeft.Y))
End If
'
If WorldFixX <> 0 Or WorldFixY <> 0 Then
'update the screen center
Dim center As B2Vec2 = bw.X2.ScreenAABB.Center
If WorldFixX <> 0 Then center.X = center.X + WorldFixX
If WorldFixY <> 0 Then center.Y = center.Y + WorldFixY
bw.X2.UpdateWorldCenter(center)
' bw.mGame.WorldCenterUpdated(WorldFix)
End If
' ###################################################
Have a look at my breakout example.
I am limiting the movement there but there is a much simpler way. Just create a chainbody as a big rect as your world frame or use 4 lines for that. Like this they will stop your bodies from crossing the screen frame.
Dear Ilan,
not exactly to do with the ratio.
If the the little guy is jumping than the blue background gets bigger since the World is sinking down. Or if ihe goes down the world the one can see the blue part below the world. Sure at the sides the same.
Means this world is not only bigger horizontally also vertically and therefore vertical scrolling is needed, too.
here the example for moving around in both directions but the screen doesn't stop at the world edge.
Greetings.B4X:' #################################################### Dim WorldFixX As Float, WorldFixY As Float ' horizontal If bw.X2.ScreenAABB.TopRight.X - bw.Body.WorldCenter.X < MIN_DISTANCE_TO_SIDES Then ' WorldFixX = MIN_DISTANCE_TO_SIDES - (bw.X2.ScreenAABB.TopRight.X - bw.Body.WorldCenter.X) Else If bw.Body.WorldCenter.X - bw.X2.ScreenAABB.BottomLeft.X < MIN_DISTANCE_TO_SIDES Then ' WorldFixX = -(MIN_DISTANCE_TO_SIDES - (bw.Body.WorldCenter.X - bw.X2.ScreenAABB.BottomLeft.X)) End If ' vertical If bw.X2.ScreenAABB.TopRight.Y - bw.Body.WorldCenter.Y < MIN_DISTANCE_TO_SIDES Then ' WorldFixY = MIN_DISTANCE_TO_SIDES - (bw.X2.ScreenAABB.TopRight.Y - bw.Body.WorldCenter.Y) Else If bw.Body.WorldCenter.Y - bw.X2.ScreenAABB.BottomLeft.Y < MIN_DISTANCE_TO_SIDES Then ' WorldFixY = -(MIN_DISTANCE_TO_SIDES - (bw.Body.WorldCenter.Y - bw.X2.ScreenAABB.BottomLeft.Y)) End If ' If WorldFixX <> 0 Or WorldFixY <> 0 Then 'update the screen center Dim center As B2Vec2 = bw.X2.ScreenAABB.Center If WorldFixX <> 0 Then center.X = center.X + WorldFixX If WorldFixY <> 0 Then center.Y = center.Y + WorldFixY bw.X2.UpdateWorldCenter(center) ' bw.mGame.WorldCenterUpdated(WorldFix) End If ' ###################################################
He is not talking about limiting the character. His game map it is bigger than the screen and the character can move left, right, Up and down (walk/Jump/fall)
I think he wants to keep the character close to the middle of the screen, except if it is close to the edge of the map, in that case, the map should stop moving at the edge and the character start moving towards the edge.
Is this what you want @Gunther ?
' ###################################################
' linker Rand or rechter Rand
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)
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
Dim vXratio As Float = x2.BCPixelsToMeters(60*64)/Main.WorldWidth
Dim vYratio As Float = x2.BCPixelsToMeters(30*64)/Main.WorldHeight
Dim minX As Float = (x2.BCPixelsToMeters(60*64)/vXratio)/2
Dim maxX As Float = x2.BCPixelsToMeters(60*64)/vXratio
Dim minY As Float = (Main.WorldHeight/vYratio) + 0.5
Dim maxY As Float = (x2.BCPixelsToMeters(30*64)/vYratio) - minY
Dim CameraPos As B2Vec2
CameraPos.X = Max(minX,(Min(maxX,bw.Body.WorldCenter.X)))
CameraPos.y = Max(minY,(Min(maxY,bw.Body.WorldCenter.y)))
x2.UpdateWorldCenter(x2.CreateVec2(CameraPos.X, CameraPos.y))
bw.mGame.WorldCenterUpdated(GS)
TileMap.SetSingleTileDimensionsInMeters(0.5, 0.5)
But the limit the x-direction I was able to do but the y-direction is problematic as well. I didn't changed the X2. this remain original unchanged.
Dim vXratio As Float = x2.BCPixelsToMeters(60*64)/Main.WorldWidth
Dim vYratio As Float = x2.BCPixelsToMeters(30*64)/Main.WorldHeight
Dim minX As Float = (x2.BCPixelsToMeters(60*64)/vXratio)/2
Dim maxX As Float = x2.BCPixelsToMeters(60*64)/vXratio
' Dim minY As Float = (Main.WorldHeight/vYratio) + 0.5
Dim minY As Float = (Main.WorldHeight/vYratio) + 2.
Dim maxY As Float = (x2.BCPixelsToMeters(30*64)/vYratio) - minY
yes sure I loaded your example and it looks like my one
Dim minY As Float = (Main.WorldHeight/vYratio) + 0.5
Dim minY As Float = (Main.WorldHeight/vYratio) + 2.0
Dear Ilan,
here the two screenshots.
With your +0.5:
View attachment 72602 = with black space in y-directionB4X:Dim minY As Float = (Main.WorldHeight/vYratio) + 0.5
With new +2.0:
View attachment 72603 = good no space anywhereB4X:Dim minY As Float = (Main.WorldHeight/vYratio) + 2.0
Greetings.
but also in your version the black space is there.