本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle类的典型用法代码示例。如果您正苦于以下问题:C# Rectangle类的具体用法?C# Rectangle怎么用?C# Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于Microsoft.Xna.Framework命名空间,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapTile
public MapTile(Texture2D texture, int type, int x, int y, int size)
{
this.TileTexture = texture;
// Changes which column of the sprite sheet the game uses to draw
int blockX = size * SpriteSheetXOffset;
this.TileColour = Color.White;
switch (type)
{
case 0: break;
case 1: this.RectSlice = new Rectangle(blockX, size * 1, size, size); this.IsSolid = true; break;
case 2: this.RectSlice = new Rectangle(blockX, size * 2, size, size); this.IsSolid = true; this.IsSpring = true; break;
case 3: this.RectSlice = new Rectangle(blockX, size * 3, size, size); this.IsSolid = true; break;
case 4: this.RectSlice = new Rectangle(blockX, size * 4, size, size); this.IsSolid = true; break;
case 5: this.RectSlice = new Rectangle(blockX, size * 5, size, size); this.IsSolid = true; break;
case 6: this.RectSlice = new Rectangle(blockX, size * 6, size, size); this.IsSolid = true; break;
case 7:
this.RectSlice = new Rectangle(blockX, size * 7, size, size); this.IsSolid = false;
this.TileColour = new Color(255, 255, 255, 20);
this.IsWater = true;
break;
default: this.RectSlice = new Rectangle(blockX, size * 0, size, size); this.IsSolid = true; break;
}
this.Width = size;
this.Height = size;
this.PositionRect = new Rectangle(x, y, this.Width, this.Height);
}
示例2: GetCorrectionVector
public static Tuple<Direction, Direction, Vector2> GetCorrectionVector(this Rectangle rect, Rectangle target)
{
Vector2 vector = new Vector2();
Direction directionX = Direction.Unknown;
Direction directionY = Direction.Unknown;
float x1 = Math.Abs(rect.Right - target.Left);
float x2 = Math.Abs(rect.Left - target.Right);
float y1 = Math.Abs(rect.Bottom - target.Top);
float y2 = Math.Abs(rect.Top - target.Bottom);
if (x1 < x2)
{
vector.X = x1;
directionX = Direction.Left;
}
else if (x1 > x2)
{
vector.X = x2;
directionX = Direction.Right;
}
if (y1 < y2)
{
vector.Y = y1;
directionY = Direction.Up;
}
else if (y1 > y2)
{
vector.Y = y2;
directionY = Direction.Down;
}
return new Tuple<Direction, Direction, Vector2>(directionX, directionY, vector);
}
示例3: Update
public void Update(GameTime gameTime)
{
position.X += Velocidade * direcao;
Rect = new Rectangle((int)position.X, (int)position.Y, sprite.Width, sprite.Height);
#region Movimentacao
//position.X = MathHelper.Clamp((float)position.X, 0, viewportRect.Width - sprite.Width);
if (position.X >= Game1.viewportRect.Width - sprite.Width)
{
position.X = Game1.viewportRect.Width - sprite.Width - 1;
NaveFilho.direcao *= -1;
}
if (position.X <= 0)
{
position.X = +1;
NaveFilho.direcao *= -1;
}
#endregion
if (boolVermelhidao)
{
Vermelhidao(gameTime);
}
}
示例4: Scrolling
public Scrolling(Texture2D texture, Rectangle rect, Vector2 Pos, float s)
{
this.texture = texture;
this.rectangle = rect;
this.Position = Pos;
this.ObjectSpeed = s;
}
示例5: Bolt
protected bool leftToRight = false; // Final boss can fire bolts left and right
#endregion Fields
#region Constructors
public Bolt(Texture2D textureImage, Point sheetSize, Vector2 position, int millisecondsPerFrame, bool leftToRight, Rectangle window, ExplosionManager explosionManager)
: base(textureImage, sheetSize, position, Vector2.Zero, millisecondsPerFrame, window, explosionManager,null)
{
this.health = 100f;
this.leftToRight = leftToRight;
this.energyToLose = health / (sheetSize.Y * sheetSize.X);
}
示例6: MouseClicked
public void MouseClicked(int x, int y, ref GameType gameType)
{
mouseClick = new Rectangle(x, y, 10, 10);
if (mouseClick.Intersects(Bouton_host))
{
c = new Client();
Thread t = new Thread(new ThreadStart(Program2.Mainq));
t.Start();
t.IsBackground = true;
}
if (mouseClick.Intersects(Bouton_Exit))
{
Game1.GetGame().Exit();
}
else if (mouseClick.Intersects(Bouton_Options))
{
gameType = GameType.Menu_Option_Type;
}
else if (mouseClick.Intersects(Bouton_Multi))
{
gameType = GameType.Menu_Play_Multi_Type2;
}
else if (mouseClick.Intersects(Bouton_Play))
{
gameType = GameType.Menu_Play_Type;
}
else if (mouseClick.Intersects(Bouton_Solo))
{
gameType = GameType.Menu_Play_Solo_Type;
}
}
示例7: Notification
public Notification(GameFacet facet, string filename, Rectangle location)
: base(facet)
{
this.filename = filename;
this.location = location;
alpha = 255;
}
示例8: Draw
public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects)
{
if (Animation == null)
{
throw new NotSupportedException("No animation is currently playing.");
}
time += (float)gameTime.ElapsedGameTime.TotalSeconds;
while (time > Animation.frameTime)
{
time -= Animation.frameTime;
if (Animation.isLooping)
{
frameIndex = (frameIndex + 1) % Animation.FrameCount;
}
else
{
frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
}
}
Rectangle source = new Rectangle(FrameIndex * Animation.FrameWidth, 0, Animation.FrameWidth, Animation.FrameHeight);
spriteBatch.Draw(animation.texture, position, source, Color.White, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0.0f);
}
示例9: Draw
public override void Draw(GameTime gameTime)
{
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
SpriteFont font = ScreenManager.TopScoresFont;
ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
Vector2 messageSize = font.MeasureString(message);
Vector2 messagePosition = (viewportSize - messageSize) / 2;
const int hPad = 32;
const int vPad = 16;
Rectangle backgroundRectangle = new Rectangle((int)messagePosition.X - hPad,
(int)messagePosition.Y - vPad,
(int)messageSize.X + hPad * 2,
(int)messageSize.Y + vPad * 2);
Color color = Color.White * TransitionAlpha;
spriteBatch.Begin();
spriteBatch.Draw(questionFrameTex, backgroundRectangle, color);
spriteBatch.DrawString(font, message, messagePosition, color);
spriteBatch.End();
}
示例10: Update
public override void Update()
{
// Bounding Box
rectangle = new Rectangle
(
(int)Position.X,
(int)Position.Y,
(int)Size.X,
(int)Size.Y
);
KeyboardState keyboardState = Keyboard.GetState();
if (Keyboard.GetState().IsKeyDown(Keys.D))
{
Position += movingVector;
body.ApplyLinearImpulse(movingImpulse);
}
else if (Keyboard.GetState().IsKeyDown(Keys.A))
{
Position -= movingVector;
body.ApplyLinearImpulse(-movingImpulse);
}
if (Keyboard.GetState().IsKeyDown(Keys.W) && !prevKeyboardState.IsKeyDown(Keys.W))
{
if ((DateTime.Now - previousJump).TotalSeconds >= jumpInterval)
{
jumpEffect.Play();
body.ApplyLinearImpulse(jumpingImpulse);
previousJump = DateTime.Now;
}
}
prevKeyboardState = keyboardState;
}
示例11: GetNodeSourceRects
public static Rectangle[] GetNodeSourceRects(NodePiece nodePiece)
{
int x = textureOffsetX;
int y = textureOffsetY;
Rectangle[] nodeSourceRects = new Rectangle[3];
// locate the "Type" sprite, make it the first entry in the return array.
x += PieceWidth + texturePaddingX;
y += Array.IndexOf(PieceTypes, nodePiece.Type) * (PieceHeight + texturePaddingY);
nodeSourceRects[0] = new Rectangle(x, y, PieceWidth, PieceHeight);
// locate the "State" sprite, make it the second entry in the return array.
y = textureOffsetY;
y += (Array.IndexOf(PieceStates, nodePiece.State) + StateSpriteOffset) * (PieceHeight + texturePaddingY);
nodeSourceRects[1] = new Rectangle(x, y, PieceWidth, PieceHeight);
// locate the "SecurityRating" sprite, make it the third entry in the return array.
x += PieceWidth + texturePaddingX;
y = textureOffsetY;
y += Array.IndexOf(PieceStates, nodePiece.SecurityRating) * (PieceHeight + texturePaddingY); // WRONG
nodeSourceRects[2] = new Rectangle(x, y, PieceWidth, PieceHeight);
return nodeSourceRects;
}
示例12: Board
public Board(Game game, int posX = 224, int posY = 64, int width = 384, int height = 384)
: base(game) {
State = EBoardState.Initialize;
Score = 0;
Bounds = new Rectangle(posX, posY, width, height);
}
示例13: ArtilleryTower
public ArtilleryTower(World world, Rectangle towerBase)
: base(world, towerBase)
{
textureMM = world.texMMartillery;
texture = world.texTowerArty;
name = "Artillery Tower";
fireSound = "artillery";
volleyMode = true;
range = 1250;
dmg = 15;
sDmg = 15;
firingRate = 250.0f;
pAcceleration = 0;
imprecision = 40;
maxMissiles = 30;
missileInterval = 50;
homing = false;
pSpeed = 8.5f;
sRange = 115;
mmColor = Color.Orange;
cost = 125;
defaultRange = range;
defaultFiringRate = firingRate;
defaultDmg = dmg;
baseDamage = defaultDmg;
}
示例14: Paddle
public Paddle(ContentManager theContent, string theAssetName, Input theInput, PaddlePosition thePosition)
: base(theContent, theAssetName)
{
SourceRectangle = new Rectangle(0, 0, 1, 1);
Scale = new Vector2(10.0f, 100.0f);
mColor = Color.SlateBlue;
mPaddlePosition = thePosition;
switch (thePosition)
{
case PaddlePosition.Left:
{
Boundary = new Rectangle(140, 185, 10, 833);
break;
}
case PaddlePosition.Right:
{
Boundary = new Rectangle(1130, 185, 10, 833);
break;
}
}
Position = Center(Boundary);
mInput = theInput;
}
示例15: DrawRectangle
/// <summary>
/// Draw a rectangle.
/// </summary>
/// <param name="rectangle">The rectangle to draw.</param>
/// <param name="color">The draw color.</param>
public void DrawRectangle(Rectangle rectangle, Color color)
{
this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, 1), color);
this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, 1), color);
this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, 1, rectangle.Height), color);
this.Draw(this.WhiteTexture, new Rectangle(rectangle.Right, rectangle.Top, 1, rectangle.Height + 1), color);
}