当前位置: 首页>>代码示例>>C#>>正文


C# SpriteBatch.DrawRectangle方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.SpriteBatch.DrawRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# SpriteBatch.DrawRectangle方法的具体用法?C# SpriteBatch.DrawRectangle怎么用?C# SpriteBatch.DrawRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Graphics.SpriteBatch的用法示例。


在下文中一共展示了SpriteBatch.DrawRectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

        public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
        {
            switch (_currentMap)
            {
                case SimulationScreenMap.Urban: _playerGame.UrbanMap.Draw(gameTime); break;
                case SimulationScreenMap.Country: _playerGame.CountryMap.Draw(gameTime); break;
                case SimulationScreenMap.Ocean: _playerGame.OceanMap.Draw(gameTime); break;
            }

            spriteBatch.DrawLine(150, 0, 150, graphicsDevice.Viewport.Height, Color.White);
            spriteBatch.DrawLine(0, graphicsDevice.Viewport.Height - 100, graphicsDevice.Viewport.Width,
                graphicsDevice.Viewport.Height - 100, Color.White);

            /* Area selection */
            Rectangle areaSelectionUrban = new Rectangle(5, graphicsDevice.Viewport.Height - 148, 43, 43);
            Rectangle areaSelectionCountry = new Rectangle(53, graphicsDevice.Viewport.Height - 148, 43, 43);
            Rectangle areaSelectionOcean = new Rectangle(101, graphicsDevice.Viewport.Height - 148, 43, 43);
            spriteBatch.DrawRectangle(0, graphicsDevice.Viewport.Height - 174, 150, 75, Color.White);
            spriteBatch.FillRectangle(areaSelectionUrban, (_currentMap == SimulationScreenMap.Urban ?
                Color.LightGray : Color.Gray));
            spriteBatch.DrawRectangle(areaSelectionUrban, Color.White);
            spriteBatch.FillRectangle(areaSelectionCountry, (_currentMap == SimulationScreenMap.Country ?
                Color.LightGray : Color.Gray));
            spriteBatch.DrawRectangle(areaSelectionCountry, Color.White);
            spriteBatch.FillRectangle(areaSelectionOcean, (_currentMap == SimulationScreenMap.Ocean ?
                Color.LightGray : Color.Gray));
            spriteBatch.DrawRectangle(areaSelectionOcean, Color.White);
        }
开发者ID:jyavoc,项目名称:Project-Gaia,代码行数:28,代码来源:SimulationScreen+(Jacob+Deitloff's+conflicted+copy+2011-03-18).cs

示例2: Draw

 public void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.FillRectangle(Position, Size, BaseColor);
     spriteBatch.DrawRectangle(Position, Size, BorderColor);
     spriteBatch.DrawString(Font, Label + ": " + CurrentValue + " / " + MaxValue,
         new Vector2(Position.X + 1, Position.Y + Size.Y - Font.MeasureString(Label + ": " +
         CurrentValue + " / " + MaxValue).Y), TextColor);
 }
开发者ID:jyavoc,项目名称:EngineLibrary,代码行数:8,代码来源:GUIStatusBar.cs

示例3: Draw

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (BackgroundColor.HasValue)
                spriteBatch.DrawRectangle(new Rectangle((int)Position.X, (int)Position.Y, Size.X, Size.Y), BackgroundColor.Value * Alpha);
            
            if (BackgroundTexture != null)
                spriteBatch.Draw(BackgroundTexture, new Rectangle((int)Position.X, (int)Position.Y, Size.X, Size.Y), Color.White * Alpha);

            base.Draw(gameTime, spriteBatch);
        }
开发者ID:MSigma,项目名称:ZooBurst,代码行数:10,代码来源:Layer.cs

示例4: Draw

 public void Draw(SpriteBatch sb, GameTime gameTime)
 {
     foreach (Enemy e in Enemies)
     {
         e.Draw(sb, gameTime);
         if (e != closestEnemy) continue;
         sb.DrawRectangle(e.HitBox, Color.Red);
     /*
         Stencil.Write("D: " + Math.Round((e.Center - player.Center).Length(), 1, MidpointRounding.AwayFromZero), sb, e.X + 4, e.Y + e.Height - 3, 0.5f);
         Stencil.Write("A: " + Math.Round(MathHelper.ToDegrees(player.Center.Angle(e.Center)), 1, MidpointRounding.AwayFromZero), sb, e.X + 4, e.Y + e.Height + 9, 0.5f);
         Stencil.Write("L: " + e.Health, sb, e.X + 4, e.Y + e.Height + 21, 0.5F);
     */
         if (e.Center.Y > 0)
             sb.DrawLine(e.Center, player.Center, Color.Red);
     }
 }
开发者ID:EmilGedda,项目名称:Storm-Pounder---First-Contact,代码行数:16,代码来源:Phase.cs

示例5: Draw

        protected override void Draw()
        {
            GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black);

            if (MapEditorGlobals.CurrentActiveTexture == null)
                return;

            var spriteBatch = new SpriteBatch(GraphicsDevice);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
            spriteBatch.Draw(MapEditorGlobals.CurrentActiveTexture, new Vector2(0, 0), Microsoft.Xna.Framework.Color.White);

            spriteBatch.DrawRectangle(MapEditorGlobals.RectangleSelectedTiles, Microsoft.Xna.Framework.Color.Yellow, 4f);

            spriteBatch.End();
        }
开发者ID:hilts-vaughan,项目名称:inspire,代码行数:16,代码来源:TilesetRenderControl.cs

示例6: Draw

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, ServiceManager.Camera.GetTransformation());

            foreach (var entity in ServiceManager.EntityCollection.Entities)
            {
                // Local players can be moved automatically, then report their status if needed
                var skinComponent = entity.GetComponent<SkinComponent>();
                // TODO: Make it so we can get the sprite descriptors from the sprite service.
                var spriteDescriptor = entity.GetComponent<SpriteComponent>().SpriteDescriptor;
                var transformComponent = entity.GetComponent<TransformComponent>();

                Rectangle bbox = new Rectangle(
                    (int)(transformComponent.LocalPosition.X + spriteDescriptor.BoundingBox.X),
                    (int)(transformComponent.LocalPosition.Y + spriteDescriptor.BoundingBox.Y),
                    spriteDescriptor.BoundingBox.Width,
                    spriteDescriptor.BoundingBox.Height);

                spriteBatch.DrawRectangle(bbox, Color.White, 2f);
            }

            spriteBatch.End();
        }
开发者ID:hilts-vaughan,项目名称:inspire,代码行数:23,代码来源:MovementService.cs

示例7: Draw

        public void Draw(SpriteBatch spriteBatch)
        {
            SpriteEffects spriteEffect;
            if (velocity.X < 0)
            {
                spriteEffect = SpriteEffects.FlipHorizontally;
            }
            else { spriteEffect = SpriteEffects.None; }

            if (Math.Abs(velocity.X) < 30)
            {
                currentAnimation.Active = false;
                currentAnimation.currentFrame = 0;
                playerSprite.Flip = spriteEffect;
                playerSprite.Draw(spriteBatch);
            }
            else //we are running
            {
                currentAnimation.Active = true;
                currentAnimation = runningAnimation;
                currentAnimation.spriteEffects = spriteEffect;
                currentAnimation.Draw(spriteBatch);
            }

            spriteBatch.DrawRectangle(playerBounds, Color.Red);

             #if DEBUG
            spriteBatch.DrawRectangle(playerBounds,Color.Red);
             #endif
        }
开发者ID:callumlawson,项目名称:Projects,代码行数:30,代码来源:Player.cs

示例8: Draw

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);

            if (HighlightedMove == null)
                return;

            var sine = (1.0F + (float)(Math.Sin((float)gameTime.TotalGameTime.TotalSeconds * 6.0F) * 1.0F)) / 2.0F;
            spriteBatch.DrawRectangle(GetAnimalRectangle(HighlightedMove.From), Color.Black * Math.Max(0.0F, sine * 0.25F));
            spriteBatch.DrawRectangle(GetAnimalRectangle(HighlightedMove.To), Color.Black * Math.Max(0.0F, sine * 0.25F));
        }
开发者ID:MSigma,项目名称:ZooBurst,代码行数:11,代码来源:GameView.cs

示例9: Draw

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(this.texture, guidePosition, guideSourceRect, Color.White);
            //spriteBatch.Draw(this.texture, guidePosition, Color.White);

            // DEBUG: Draw locations of buttons and tabs
            if (Settings.SHOW_HITBOXES)
            {
                Vector2 openButtonPosition, closeButtonPosition, tab1, tab2, tab3, tab4, tabSize;
                tabSize = new Vector2(Settings.CALLOUT_TAB_WIDTH, Settings.CALLOUT_TAB_HEIGHT);
                if (this.IsLeftward)
                {
                    openButtonPosition = Settings.CALLOUT_OPEN_BUTTON_LEFT;
                    closeButtonPosition = Settings.CALLOUT_CLOSE_BUTTON_LEFT;
                    if (this.IsUpsideDown)
                    {
                        tab1 = -Settings.CALLOUT_TAB1_BUTTON;
                        tab2 = -Settings.CALLOUT_TAB2_BUTTON;
                        tab3 = -Settings.CALLOUT_TAB3_BUTTON;
                        tab4 = -Settings.CALLOUT_TAB4_BUTTON;
                    }
                    else
                    {
                        tab1 = Settings.CALLOUT_TAB1_BUTTON_LEFT;
                        tab2 = Settings.CALLOUT_TAB2_BUTTON_LEFT;
                        tab3 = Settings.CALLOUT_TAB3_BUTTON_LEFT;
                        tab4 = Settings.CALLOUT_TAB4_BUTTON_LEFT;
                    }
                }
                else
                {
                    openButtonPosition = Settings.CALLOUT_OPEN_BUTTON;
                    closeButtonPosition = Settings.CALLOUT_CLOSE_BUTTON;
                    if (this.IsUpsideDown)
                    {
                        tab1 = -Settings.CALLOUT_TAB1_BUTTON_LEFT;
                        tab2 = -Settings.CALLOUT_TAB2_BUTTON_LEFT;
                        tab3 = -Settings.CALLOUT_TAB3_BUTTON_LEFT;
                        tab4 = -Settings.CALLOUT_TAB4_BUTTON_LEFT;
                    }
                    else
                    {
                        tab1 = Settings.CALLOUT_TAB1_BUTTON;
                        tab2 = Settings.CALLOUT_TAB2_BUTTON;
                        tab3 = Settings.CALLOUT_TAB3_BUTTON;
                        tab4 = Settings.CALLOUT_TAB4_BUTTON;
                    }
                }
                if (this.CurrentState == Guide.GuideState.CLOSED)
                {
                    spriteBatch.DrawCircle(this.ParentZoomCircle.position + openButtonPosition, Settings.CALLOUT_DETECTION_RADIUS, 64, Color.Pink);
                }
                else if (this.CurrentState == Guide.GuideState.OPEN)
                {
                    spriteBatch.DrawCircle(this.ParentZoomCircle.position + closeButtonPosition, Settings.CALLOUT_DETECTION_RADIUS, 64, Color.Pink);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab1.X - tabSize.X / 2, tab1.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab2.X - tabSize.X / 2, tab2.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab3.X - tabSize.X / 2, tab3.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                    spriteBatch.DrawRectangle(this.ParentZoomCircle.position + new Vector2(tab4.X - tabSize.X / 2, tab4.Y - tabSize.Y / 2), tabSize, Color.Pink, 1f);
                }
            }
        }
开发者ID:javidhsueh,项目名称:planktonpopulations,代码行数:62,代码来源:Guide.cs

示例10: DrawSelf

 public void DrawSelf(SpriteBatch spriteBatch, Color color)
 {
     spriteBatch.DrawRectangle(_bbox, color);
 }
开发者ID:CyberSpiral,项目名称:WushuFighter,代码行数:4,代码来源:Body.cs

示例11: Draw

 public void Draw(SpriteBatch sb, GameTime gameTime)
 {
     background.Draw(sb);
     sb.DrawRectangle(player.HitBox, Color.Red);
     phases.Draw(sb, gameTime);
     player.Draw(sb, gameTime);
 }
开发者ID:EmilGedda,项目名称:Storm-Pounder---First-Contact,代码行数:7,代码来源:Level.cs

示例12: Draw

		public override void Draw( SpriteBatch spriteBatch, float alpha ) {
			Color dynamicColor = new Color( new Vector4( ColorFgDefault.ToVector3(), alpha ) );
			Vector2 drawPos = Position;
			Vector2 textSize = SpriteFont.MeasureString( Text );
			string[] Lines = Text.Split( new char[] { '\n' } );

			if( ColorBgDefault != Color.Transparent ) {
				Color dynBg = new Color( new Vector4( ColorBgDefault.ToVector3(), alpha ) );
				mButtonArea = new Rectangle( (int)Position.X - Value, (int)Position.Y - Value, ControlSize.X, ControlSize.Y );
				if( ControlSize.X == 0 )
					mButtonArea.Width = (int)textSize.X + 5;
				if( ControlSize.Y == 0 )
					mButtonArea.Height = (int)textSize.Y + 5;

				if( mTextureBlank == null )
					mTextureBlank = EngineCore.ContentLoader.Load<Texture2D>( @"Interface\blank" );

				spriteBatch.Draw( mTextureBlank, mButtonArea, dynBg );
				if( BorderColor != Color.Transparent ) {
					Texture2D tex = DrawHelper.Rect2Texture( 1, 1, 0, BorderColor );
					spriteBatch.DrawRectangle( tex, mButtonArea, 1, BorderColor );
				}
			} else
				mButtonArea = new Rectangle( mButtonArea.X, mButtonArea.Y, ControlSize.X, ControlSize.Y );

			for( int i = 0; i < Lines.Length; i++ ) {
				if( i > 0 )
					drawPos.Y += SpriteFont.LineSpacing;
				spriteBatch.DrawString( SpriteFont, Lines[ i ], drawPos, dynamicColor );
			}

		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:32,代码来源:Label.cs

示例13: Draw

 public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
 {
     spriteBatch.FillRectangle(Position, Size, (Hovered ? Color.LightBlue : Color.Blue));
     spriteBatch.DrawRectangle(Position, Size, Color.Black);
 }
开发者ID:jyavoc,项目名称:Project-Gaia,代码行数:5,代码来源:ScreenItemWindowButtons.cs

示例14: DrawWorldViewPort


//.........这里部分代码省略.........
                        for (int i = 0; i < viewPortInfo.TileCountX; i++)
                        {
                            for (int j = 0; j < viewPortInfo.TileCountY; j++)
                            {
                                int tileX = (int)(i + viewPortInfo.pxTopLeftX / Map.TileWidth);
                                int tileY = (int)(j + viewPortInfo.pxTopLeftY / Map.TileHeight);

                                int tileGid = tileLayer[tileX, tileY];

                                Rectangle pxTileDestRect = new Rectangle(
                                    (int) Math.Ceiling(i * viewPortInfo.pxTileWidth - viewPortInfo.pxDispX * viewPortInfo.ActualZoom),
                                    (int) Math.Ceiling(j * viewPortInfo.pxTileHeight - viewPortInfo.pxDispY * viewPortInfo.ActualZoom),
                                    (int) viewPortInfo.pxTileWidth,
                                    (int) viewPortInfo.pxTileHeight
                                );

                                if (tileGid != 0 && tileGid != -1)   // NULL or INVALID Tile Gid is ignored
                                {
                                    Tile tile = Map.Tiles[tileGid];

                                    spriteBatch.Draw(
                                        tile.sourceTexture,
                                        pxTileDestRect,
                                        tile.SourceRectangle,
                                        layerColor,
                                        0, Vector2.Zero,
                                        SpriteEffects.None,
                                        depth
                                    );
                                }

                                // DRAW THE TILE LAYER GRID IF ENABLE
                                if (DrawingOptions.ShowTileGrid && layerIndex == Map.TileLayers.Count - 1)
                                    spriteBatch.DrawRectangle(pxTileDestRect, Color.Black, 0);
                            }
                        }
                    }
                }
            }
            spriteBatch.End();

            OverallPerformance.StopTiming("TileRenderingTime");

            // Calculate the entity Displacement caused by pxTopLeft at a global scale to prevent jittering.
            // Each entity should be displaced by the *same amount* based on the pxTopLeftX/Y values
            // this is to prevent entities 'jittering on the screen' when moving the camera.
            float globalDispX = (int) Math.Ceiling(viewPortInfo.pxTopLeftX * viewPortInfo.ActualZoom);
            float globalDispY = (int) Math.Ceiling(viewPortInfo.pxTopLeftY * viewPortInfo.ActualZoom);

            // DRAW VISIBLE REGISTERED ENTITIES
            OverallPerformance.RestartTiming("TotalEntityRenderTime");
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, samplerState, null, null);
            {
                EntitiesOnScreen = Collider.GetIntersectingEntites(new FRectangle(viewPortInfo.pxViewPortBounds));

                // DRAW EACH ENTITIY THAT IS WITHIN THE SCREENS VIEWPORT
                foreach (Entity entity in EntitiesOnScreen)
                {
                    EntityRenderPerformance.RestartTiming(entity.Name);

                    if (!entity.Visible) continue;
                    entity.IsOnScreen = true;

                    // Determine the absolute position on the screen for entity position and the bounding box.
                    Vector2 pxAbsEntityPos = new Vector2(
                        entity.Pos.X * viewPortInfo.ActualZoom - globalDispX,
开发者ID:behindcurtain3,项目名称:Some-2D-RPG,代码行数:67,代码来源:TeeEngine.cs

示例15: Draw

        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            spriteBatch.Begin();
            player.Draw(spriteBatch, gameTime);
            //Kenneth: Test av tegning av "Rock", merk at draw i Sprite nå har fått overloaded draw med scaling
            rock.Draw(spriteBatch, new Vector2(Game.Window.ClientBounds.Width / 2, Game.Window.ClientBounds.Height / 2),gameTime, 0.7f);
            particleEmitter.Draw(spriteBatch, gameTime);    //Bare test av denne particleEmitter-tingen. Fungerer ikke bra nok.

            //Her tegner jeg gridnettet som Debugging, trenger naturlig nok ikke å være synlig i spillverden :)
            for (int i = 0; i < collisionGrid.Count; i++ )
            {
                spriteBatch.DrawRectangle(collisionGrid.ElementAt(i).rectangle, collisionGrid.ElementAt(i).Color, 1f);
            }
            spriteBatch.DrawRectangle(mouseCollisionRectangle, Color.Green);
            if (pauseMenu.Open)
            {
                pauseMenu.Draw(spriteBatch, gameTime);
            }
            spriteBatch.End();
        }
开发者ID:KennethE,项目名称:KennethKode,代码行数:20,代码来源:InGame.cs


注:本文中的Microsoft.Xna.Framework.Graphics.SpriteBatch.DrawRectangle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。