static bool BackgroundLargerThanScreen(SpriteMover mover, CameraWorldWrapper camera) { float cameraArea = camera.GetScreenDimsInWorldCoords().magnitude; var backgroundDims = mover.Dimentions; return(backgroundDims.magnitude > cameraArea); }
public HorizontalTilingBackground(Camera camera, SpriteMover spriteMover, SpriteMover spriteCopyMover) { if (!SpriteMoverDimsEqual(spriteMover, spriteCopyMover)) { throw new ArgumentException("backgrounds must have equal sizes"); } _cameraWorldWrapper = new CameraWorldWrapper(camera); if (!BackgroundLargerThanScreen(spriteMover, _cameraWorldWrapper)) { throw new ArgumentException("background must be larger than screen (in world units)"); } _bgMover = spriteMover; _copyBgMover = spriteCopyMover; // place the one copy of bg at the center of the camera, the other tiled to the left _bgMover.MoveCenter(_cameraWorldWrapper.Position); TileSpriteToTheLeft(_bgMover, _copyBgMover); }
SpriteMover GetOtherBackground(SpriteMover thisSprite) { return(thisSprite == _bgMover ? _copyBgMover : _bgMover); }
bool CameraOutOfLeftBound(SpriteMover sprite) { return(_cameraWorldWrapper.LeftBound - BgChangeTolerance <= sprite.LeftBound); }
bool CameraOutOfRightBound(SpriteMover sprite) { return(_cameraWorldWrapper.RightBound + BgChangeTolerance >= sprite.RightBound); }
/// <summary> /// tiles one sprite to the left of another: /// places the <paramref name="movingSprite"/> so that it's top right corner /// is at the <paramref name="staticSprite"/>'s top left corner, /// making a seemless connection /// </summary> static void TileSpriteToTheLeft(SpriteMover staticSprite, SpriteMover movingSprite) { movingSprite.MoveTopRightCorner(staticSprite.TopLeft); }
static bool SpriteMoverDimsEqual(SpriteMover mover, SpriteMover otherMover) { return(Math.Abs( (mover.Dimentions - otherMover.Dimentions).magnitude) < 0.02); }