allow camera shaking to exit map borders
This commit is contained in:
@@ -35,31 +35,34 @@ namespace OpenRA.Graphics
|
|||||||
public static int TicksSinceLastMove = 0;
|
public static int TicksSinceLastMove = 0;
|
||||||
public static int2 LastMousePos;
|
public static int2 LastMousePos;
|
||||||
|
|
||||||
public void Scroll(float2 delta)
|
public void Scroll(float2 delta){
|
||||||
|
this.Scroll(delta, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Scroll(float2 delta, bool ignoreBorders)
|
||||||
{
|
{
|
||||||
float2 topLeftBorder = (Game.CellSize* mapStart).ToFloat2();
|
float2 newScrollPosition = scrollPosition + delta;
|
||||||
float2 bottomRightBorder = (Game.CellSize* mapEnd).ToFloat2();
|
|
||||||
float2 newScrollPosition = scrollPosition + delta;
|
|
||||||
|
|
||||||
if(newScrollPosition.Y < topLeftBorder.Y)
|
|
||||||
newScrollPosition.Y = topLeftBorder.Y;
|
|
||||||
|
|
||||||
if(newScrollPosition.X < topLeftBorder.X)
|
|
||||||
newScrollPosition.X = topLeftBorder.X;
|
|
||||||
|
|
||||||
if(newScrollPosition.Y > bottomRightBorder.Y-screenSize.Y)
|
if(!ignoreBorders){
|
||||||
newScrollPosition.Y = bottomRightBorder.Y-screenSize.Y;
|
float2 topLeftBorder = (Game.CellSize* mapStart).ToFloat2();
|
||||||
|
float2 bottomRightBorder = (Game.CellSize* mapEnd).ToFloat2();
|
||||||
if(newScrollPosition.X > bottomRightBorder.X-screenSize.X)
|
|
||||||
newScrollPosition.X = bottomRightBorder.X-screenSize.X;
|
if(newScrollPosition.Y < topLeftBorder.Y)
|
||||||
|
newScrollPosition.Y = topLeftBorder.Y;
|
||||||
scrollPosition = newScrollPosition;
|
if(newScrollPosition.X < topLeftBorder.X)
|
||||||
|
newScrollPosition.X = topLeftBorder.X;
|
||||||
|
if(newScrollPosition.Y > bottomRightBorder.Y-screenSize.Y)
|
||||||
|
newScrollPosition.Y = bottomRightBorder.Y-screenSize.Y;
|
||||||
|
if(newScrollPosition.X > bottomRightBorder.X-screenSize.X)
|
||||||
|
newScrollPosition.X = bottomRightBorder.X-screenSize.X;
|
||||||
|
}
|
||||||
|
scrollPosition = newScrollPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScrollDirection GetBlockedDirections()
|
public ScrollDirection GetBlockedDirections()
|
||||||
{
|
{
|
||||||
int2 topLeftBorder = (Game.CellSize* mapStart);
|
int2 topLeftBorder = (Game.CellSize* mapStart);
|
||||||
int2 bottomRightBorder = (Game.CellSize* mapEnd);
|
int2 bottomRightBorder = (Game.CellSize* mapEnd);
|
||||||
|
|
||||||
ScrollDirection blockedDirections = ScrollDirection.None;
|
ScrollDirection blockedDirections = ScrollDirection.None;
|
||||||
|
|
||||||
@@ -154,4 +157,4 @@ namespace OpenRA.Graphics
|
|||||||
return localPlayer.Shroud.Bounds;
|
return localPlayer.Shroud.Bounds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void Tick (Actor self)
|
public void Tick (Actor self)
|
||||||
{
|
{
|
||||||
Game.viewport.Scroll(GetScrollOffset());
|
Game.viewport.Scroll(GetScrollOffset(), true);
|
||||||
shakeEffects.RemoveAll(t => t.ExpiryTime == ticks);
|
shakeEffects.RemoveAll(t => t.ExpiryTime == ticks);
|
||||||
ticks++;
|
ticks++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user