本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle类的典型用法代码示例。如果您正苦于以下问题:C# Rectangle类的具体用法?C# Rectangle怎么用?C# Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于Microsoft.Xna.Framework命名空间,在下文中一共展示了Rectangle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:colincapurso,项目名称:Game-Engine-XNA,代码行数:27,代码来源:MapTile.cs
示例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);
}
开发者ID:zunath,项目名称:MMXEngine,代码行数:35,代码来源:RectangleExtensions.cs
示例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);
}
}
开发者ID:vitormartins1,项目名称:project-meteor,代码行数:29,代码来源:NaveFilho.cs
示例4: Scrolling
public Scrolling(Texture2D texture, Rectangle rect, Vector2 Pos, float s)
{
this.texture = texture;
this.rectangle = rect;
this.Position = Pos;
this.ObjectSpeed = s;
}
开发者ID:glocklueng,项目名称:STM32F4_RF,代码行数:7,代码来源:Background.cs
示例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);
}
开发者ID:urgamedev,项目名称:code-monogame,代码行数:13,代码来源:Bolt.cs
示例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;
}
}
开发者ID:Greflop,项目名称:Final,代码行数:32,代码来源:Menu_Play_Multi.cs
示例7: Notification
public Notification(GameFacet facet, string filename, Rectangle location)
: base(facet)
{
this.filename = filename;
this.location = location;
alpha = 255;
}
开发者ID:Cheezmeister,项目名称:Chromathud,代码行数:7,代码来源:Notification.cs
示例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);
}
开发者ID:WINPROG20152016,项目名称:Penaranda_TapTitanXNA,代码行数:27,代码来源:AnimationPlayer.cs
示例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();
}
开发者ID:decwong,项目名称:DEPW,代码行数:26,代码来源:QuestionScreen.cs
示例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;
}
开发者ID:rolandKulcsar,项目名称:Crate-Game,代码行数:34,代码来源:Player.cs
示例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;
}
开发者ID:TensAndTwenties,项目名称:Ruin,代码行数:28,代码来源:GamePiece.cs
示例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);
}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:7,代码来源:Board.cs
示例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;
}
开发者ID:kinaesthesia,项目名称:KDefTower,代码行数:28,代码来源:ArtilleryTower.cs
示例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;
}
开发者ID:Gevil,项目名称:Projects,代码行数:27,代码来源:Paddle.cs
示例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);
}
开发者ID:dotKokott,项目名称:MathFighter,代码行数:12,代码来源:ExtendedSpriteBatch.cs
示例16: Inventory
public Inventory(int SCREEN_WIDTH, int SCREEN_HEIGHT, Pantheon gameReference)
{
locationBoxes = new List<Rectangle>();
equippedBoxes = new List<Rectangle>();
types = new List<int>();
infoBox = new Rectangle();
movingBox = new Rectangle();
trashBox = new Rectangle();
tempStorage = new Item();
this.SCREEN_WIDTH = SCREEN_WIDTH;
this.SCREEN_HEIGHT = SCREEN_HEIGHT;
SetBoxes();
selected = -1;
hoveredOver = -1;
color = new Color(34, 167, 222, 50);
trashColor = Color.White;
inventorySelector = gameReference.Content.Load<Texture2D>("Inventory/InvSelect");
trashCan = gameReference.Content.Load<Texture2D>("Inventory/TrashCan");
nullImage = new Texture2D(gameReference.GraphicsDevice, 1,1);
nullImage.SetData(new[] { new Color(0,0,0,0) });
}
开发者ID:Tangent128,项目名称:PantheonPrototype,代码行数:27,代码来源:Inventory.cs
示例17: Init
public void Init(ContentManager content, Vector2 position, string normalTextureName, string hoverTextureName)
{
m_Normal = content.Load<Texture2D>(normalTextureName);
m_Hover = content.Load<Texture2D>(hoverTextureName);
m_ButtonRec = new Rectangle((int)position.X, (int)position.Y, m_Normal.Width, m_Normal.Height);
}
开发者ID:rushTENm,项目名称:Exit_OF,代码行数:7,代码来源:Button.cs
示例18: GetIntersectionDepth
public static Vector2 GetIntersectionDepth(Rectangle rectA, Rectangle rectB)
{
// Calculate half sizes.
float halfWidthA = rectA.Width / 2.0f;
float halfHeightA = rectA.Height / 2.0f;
float halfWidthB = rectB.Width / 2.0f;
float halfHeightB = rectB.Height / 2.0f;
// Calculate centers.
Vector2 centerA = new Vector2(rectA.Left + halfWidthA, rectA.Top + halfHeightA);
Vector2 centerB = new Vector2(rectB.Left + halfWidthB, rectB.Top + halfHeightB);
// Calculate current and minimum-non-intersecting distances between centers.
float distanceX = centerA.X - centerB.X;
float distanceY = centerA.Y - centerB.Y;
float minDistanceX = halfWidthA + halfWidthB;
float minDistanceY = halfHeightA + halfHeightB;
// If we are not intersecting at all, return (0, 0).
if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
return Vector2.Zero;
// Calculate and return intersection depths.
float depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
float depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
return new Vector2(depthX, depthY);
}
开发者ID:thestonefox,项目名称:Project-Xna,代码行数:27,代码来源:Collision.cs
示例19: Camera
public Camera(Rectangle viewportRect)
{
speed = 4f;
zoom = 1f;
viewportRectangle = viewportRect;
mode = CameraMode.Follow;
}
开发者ID:RainbowCupcake,项目名称:MLPTheMasterQuest,代码行数:7,代码来源:Camera.cs
示例20: MenuManager
public MenuManager(Main game, String[] strMenuTextures,
String strMenuFont, Integer2 textureBorderPadding)
: base(game)
{
this.game = game;
//nmcg - create an array of textures
this.menuTextures = new Texture2D[strMenuTextures.Length];
//nmcg - load the textures
for (int i = 0; i < strMenuTextures.Length; i++)
{
this.menuTextures[i] =
game.Content.Load<Texture2D>(@"" + strMenuTextures[i]);
}
//nmcg - load menu font
this.menuFont = game.Content.Load<SpriteFont>(@"" + strMenuFont);
//nmcg - stores all menu item (e.g. Save, Resume, Exit) objects
this.menuItemList = new List<MenuItem>();
//sets menu texture to fullscreen minus and padding on XY
this.textureRectangle = menuTextures[0].Bounds;
}
开发者ID:Resinderate,项目名称:ShadowMadness,代码行数:25,代码来源:MenuManager.cs
注:本文中的Microsoft.Xna.Framework.Rectangle类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论