本文整理汇总了C#中SpriteBatch.Begin方法的典型用法代码示例。如果您正苦于以下问题:C# SpriteBatch.Begin方法的具体用法?C# SpriteBatch.Begin怎么用?C# SpriteBatch.Begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpriteBatch
的用法示例。
在下文中一共展示了SpriteBatch.Begin方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(SpriteBatch sb, Projectile p) {
Vector2 pc = p.position+new Vector2(p.width/2f,p.height/2f);
if (fired) {
sb.End();
sb.Begin(SpriteSortMode.Immediate,BlendState.Additive);
foreach (Spark spark in sparks) spark.Draw(sb,p,this);
for (int i = 0; i < sparks.Count; i++) if (sparks[i].dead) sparks.RemoveAt(i--);
sb.End();
sb.Begin();
if (sparks.Count == 0) p.Kill();
} else {
fired = true;
int r, g, b;
Color c;
float degrees;
byte[] bytes = BitConverter.GetBytes(seed);
Random rnd = new Random();
degrees = (float)(rnd.NextDouble()*360d);
HsvToRgb(bytes[0]*360f/255f,bytes[1]/255f,1f,out r,out g,out b);
c = new Color(r,g,b);
for (int i = 0; i < 20; i++) sparks.Add(new MySpark(pc,Util.Vector((float)(1.5f+rnd.NextDouble()*.75f),360f/20f*i+degrees),c,80+rnd.Next(40)));
degrees = (float)(rnd.NextDouble()*360d);
HsvToRgb(bytes[2]*360f/255f,bytes[3]/255f,1f,out r,out g,out b);
c = new Color(r,g,b);
for (int i = 0; i < 40; i++) sparks.Add(new MySpark(pc,Util.Vector((float)(3f+rnd.NextDouble()*1.5f),360f/40f*i+degrees),c,80+rnd.Next(40)));
}
}
示例2: DrawOnScreen
public void DrawOnScreen(SpriteBatch sb, double layer) {
sb.End();
sb.Begin(SpriteSortMode.Immediate,BlendState.Additive);
foreach (ModWorld.Effect e in ModWorld.effects) e.Draw(sb);
sb.End();
sb.Begin();
}
示例3: PreDrawItemInSlot
public void PreDrawItemInSlot(SpriteBatch sb, Color color, Item item, Vector2 pos, float sc, ref bool letDraw) {
if (item.name != "Firefly in a Jar" && item.name != "Firefly in a Bottle") return;
if (!item.RunMethod("ExternalGetFirefly")) return;
ModWorld.EffectFirefly firefly = (ModWorld.EffectFirefly)Codable.customMethodReturn;
if (firefly == null) return;
sb.End();
sb.Begin(SpriteSortMode.Immediate,BlendState.Additive);
firefly.DrawItem(sb,pos.X,(int)(pos.Y+2*sc),sc,item);
sb.End();
sb.Begin();
ModWorld.effectsExtraUpdate.Add(firefly);
}
示例4: DrawOnScreen
public void DrawOnScreen(SpriteBatch sb, double layer) {
if (ModWorld.display == "off") return;
if (Config.tileInterface != null) return;
if (Config.npcInterface != null) return;
sb.End();
sb.Begin(SpriteSortMode.Immediate,BlendState.NonPremultiplied);
foreach (Player player in Main.player) {
if (player == null) continue;
if (!player.active) continue;
if (player.dead || player.ghost) continue;
if (ModWorld.display != "all") {
if (player.whoAmi == Main.myPlayer && ModWorld.display != "my") continue;
if (player.whoAmi != Main.myPlayer && ModWorld.display != "other") continue;
}
if (player.invis) continue;
float alpha = GetBarAlpha(player);
if (alpha <= 0) continue;
int hp = player.statLife, hpMax = player.statLifeMax;
int xx = (int)(player.position.X-Main.screenPosition.X)-12, yy = (int)(player.position.Y-16-Main.screenPosition.Y), ww = 44, hh = 12;
Color color = new Color(255,255,255);
color.A = (byte)(alpha*255);
sb.Draw(texBack,new Rectangle(xx,yy,ww,hh),color);
sb.Draw(texRed,new Rectangle(xx+2,yy+2,ww-4,hh-4),color);
sb.Draw(texGreen,new Rectangle(xx+2,yy+2,(int)((1d*hp/hpMax)*(ww-4)),hh-4),color);
}
sb.End();
sb.Begin();
}
示例5: OnPreviewViewportDraw
private void OnPreviewViewportDraw(Device device, SpriteBatch spriteBatch, Rectangle cliprectangle)
{
UiEncodingWindowSource source = _currentSource;
if (source == null)
return;
spriteBatch.Begin(SpriteSortMode.Deferred, null, _previewViewport.DxControl.RenderContainer.GraphicsDevice.SamplerStates.PointClamp, null, null, null, SharpDX.Matrix.Scaling(_scale));
float x = 0, maxX = 0;
float y = source.Info.Header.LineSpacing;
int squareSize = source.Info.Header.SquareSize;
int lineSpacing = source.Info.Header.LineHeight + source.Info.Header.LineSpacing;
foreach (char ch in _previewText)
{
if (ch == '\r')
continue;
if (ch == '\n')
{
x = 0;
y += lineSpacing;
continue;
}
short index;
if (source.Codes.TryGetValue(ch, out index))
{
int ox, oy;
int h, w;
if (index < 256)
{
byte before, width, after;
source.Info.GetSizes(index, out before, out width, out after);
w = width;
h = source.Info.Header.LineHeight;
if (before > 0x7F)
x = Math.Max(x - (0xFF - before), 0);
else
x += before;
source.Info.GetOffsets(index, out ox, out oy);
source.Texture.Draw(device, spriteBatch, new Vector2(x, y), new Rectangle(ox, oy, w, h), 0, cliprectangle);
if (after > 0x7F)
x = Math.Max(x - (0xFF - after), 0);
else
x += after;
}
else
{
index -= 256;
w = h = squareSize;
int value = source.Info.AdditionalTable[index];
ox = (value & 0xFF) * squareSize;
oy = (value >> 8) * squareSize;
source.Texture.Draw(device, spriteBatch, new Vector2(x, y), new Rectangle(ox, oy, w, h), 0, cliprectangle);
}
x += w;
maxX = Math.Max(x, maxX);
}
}
spriteBatch.End();
double desiredWidth, desiredHeight;
_previewViewport.GetDesiredSize(out desiredWidth, out desiredHeight);
double newDesiredWidth = x * _scale;
double newDesiredHeight = (y + lineSpacing) * _scale;
if (Math.Abs(newDesiredWidth - desiredWidth) > 1 || Math.Abs(newDesiredHeight - newDesiredHeight) > 1)
_previewViewport.SetDesiredSize(newDesiredWidth, newDesiredHeight);
}
示例6: OnEditViewportDrawSprites
private void OnEditViewportDrawSprites(Device device, SpriteBatch spriteBatch, Rectangle cliprectangle)
{
UiEncodingWindowSource current = _currentSource;
if (current == null)
return;
try
{
spriteBatch.Begin();
current.Texture.Draw(device, spriteBatch, Vector2.Zero, new Rectangle(0, 0, current.Texture.Descriptor2D.Width, current.Texture.Descriptor2D.Height), 0, cliprectangle);
spriteBatch.End();
}
catch (Exception ex)
{
Log.Error(ex);
}
}
示例7: Draw
public override void Draw(SpriteBatch batch, GameTime time)
{
batch.Begin();
// Draw wood background
for (var x = 0; x < 11; x++)
{
for (var y = 0; y < 8; y++)
{
var tileX = x * ChainReactGame.WabeSize;
var tileY = y * ChainReactGame.WabeSize;
batch.DrawTexture(_background, new Rectangle(tileX, tileY, ChainReactGame.WabeSize, ChainReactGame.WabeSize));
}
}
// Draw gray game field
for (var x = 1; x < 7; x++)
{
for (var y = 1; y < 7; y++)
{
var tileX = x * ChainReactGame.WabeSize;
var tileY = y * ChainReactGame.WabeSize;
batch.DrawTexture(_gameAreaTexture, new Rectangle(tileX, tileY, ChainReactGame.WabeSize, ChainReactGame.WabeSize));
}
}
// Draw wabes
const float cut = (ChainReactGame.WabeSize / 3);
var fullWabeSizeX = ChainReactGame.WabeSize * _game.GameMap.Wabes.GetLength(0);
var fullWabeSizeY = ChainReactGame.WabeSize * _game.GameMap.Wabes.GetLength(1);
foreach (var wabe in _game.GameMap.Wabes)
{
var wabeX = (wabe.X + 1) * ChainReactGame.WabeSize;
var wabeY = (wabe.Y + 1) * ChainReactGame.WabeSize;
for (var x = 0; x <= 2; x++)
{
for (var y = 0; y <= 2; y++)
{
var field = wabe.ConvertVector2ToWabeField(new Vector2(x, y));
var texture = SelectTextureFromField(field);
var mutltiplicatorX = cut * x;
var mutltiplicatorY = cut * y;
if (field.Type == WabeFieldType.Center)
{
var color = wabe.Owner?.Color ?? Color.White;
color.A = (wabe.Owner != null) ? (byte)205 : (byte)255;
batch.DrawTexture(texture, new Rectangle((wabeX) + mutltiplicatorX, (wabeY) + mutltiplicatorY, cut, cut), color);
}
else if (field.Type == WabeFieldType.Unused)
{
var color = wabe.Owner?.Color ?? Color.LightGray;
color.A = 128;
batch.DrawTexture(texture, new Rectangle((wabeX) + mutltiplicatorX, (wabeY) + mutltiplicatorY, cut, cut), color);
}
else
{
batch.DrawTexture(texture,
new Rectangle((wabeX) + mutltiplicatorX, (wabeY) + mutltiplicatorY, cut, cut));
}
var posX = mutltiplicatorX + wabeX;
var posY = mutltiplicatorY + wabeY;
// Draw field border
if (GameSettings.Instance.FieldLines)
batch.DrawTexture(_fieldBorder, new Rectangle(posX, posY, cut, cut));
}
}
// Draw wabe border
if (GameSettings.Instance.WabeLines)
batch.DrawTexture(_wabeBorder, new Rectangle(wabeX, wabeY, ChainReactGame.WabeSize, ChainReactGame.WabeSize));
}
// Draw game border
if (GameSettings.Instance.BorderLines)
batch.DrawTexture(_gameBorder, new Rectangle(ChainReactGame.WabeSize, ChainReactGame.WabeSize, fullWabeSizeX, fullWabeSizeY));
// Draw messages
if (!string.IsNullOrEmpty(_lastMessage))
{
batch.DrawString(!string.IsNullOrEmpty(_game.Message) ? _game.Message : _lastMessage, _font,
new Vector2(96, 680), Color.Black);
}
else
{
if (!string.IsNullOrEmpty(_game.Message))
{
batch.DrawString(_game.Message, _font, new Vector2(96, 680), Color.Black);
}
}
if (!string.IsNullOrEmpty(ResourceManager.LastSoundError))
{
batch.DrawString("Failed to play a sound: " + ResourceManager.LastSoundError, _font, new Vector2(96, 720), Color.Red);
}
if (_game?.CurrentPlayer != null)
{
batch.DrawString(_game.CurrentPlayer.Name + $"'s turn ({_game.CurrentPlayer.GetColorString()}) ({_game.CurrentPlayer.Wins} Wins)", _font, new Vector2(96, 60), Color.Black);
}
foreach (var wabe in _game.GameMap.Wabes.Cast<Wabe>().ToList().Where(x => x.AnimationManager.IsRunning).Select(x => x.AnimationManager))
//.........这里部分代码省略.........
示例8: InternalDraw
/// <summary>
/// Draw the door with a scissor test
/// </summary>
/// <param name="batch">Spritebatch to use</param>
/// <param name="tileset">Tileset to use</param>
/// <param name="id">ID of the tile</param>
/// <param name="location">Location of the tile on the screen</param>
/// <param name="scissor">Scissor zone</param>
/// <param name="scale">Scaling factor</param>
/// <param name="color">Color</param>
void InternalDraw(SpriteBatch batch, TileSet tileset, int id, Point location, Rectangle scissor, Vector2 scale, Color color)
{
if (batch == null)
return;
batch.End();
Display.PushScissor(scissor);
batch.Begin();
batch.DrawTile(TileSet, id, location, color, 0.0f, scale, SpriteEffects.None, 0.0f);
batch.End();
Display.PopScissor();
batch.Begin();
}
示例9: Draw
/// <summary>
/// Draw the maze
/// </summary>
/// <param name="batch">SpriteBatch to use</param>
/// <param name="location">Location to display from</param>
/// <see cref="http://eob.wikispaces.com/eob.vmp"/>
public void Draw(SpriteBatch batch, DungeonLocation location)
{
if (WallTileset == null)
return;
// Clear the spritebatch
batch.End();
Display.PushScissor(new Rectangle(0, 0, 352, 240));
batch.Begin();
//
//
//
ViewField pov = new ViewField(this, location);
// TODO Backdrop
// The background is assumed to be x-flipped when party.x & party.y & party.direction = 1.
// I.e. all kind of moves and rotations from the current position will result in the background being x-flipped.
bool flipbackdrop = ((location.Coordinate.X + location.Coordinate.Y + (int)location.Direction) & 1) == 0;
SpriteEffects effect = flipbackdrop ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
batch.DrawTile(WallTileset, 0, Point.Empty, Color.White, 0.0f, effect, 0.0f);
// maze block draw order
// A E B D C
// F J G I H
// K M L
// N ^ O
#region row -3
DrawSquare(batch, pov, ViewFieldPosition.A, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.E, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.B, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.D, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.C, location.Direction);
#endregion
#region row -2
DrawSquare(batch, pov, ViewFieldPosition.F, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.J, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.G, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.I, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.H, location.Direction);
#endregion
#region row -1
DrawSquare(batch, pov, ViewFieldPosition.K, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.M, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.L, location.Direction);
#endregion
#region row 0
DrawSquare(batch, pov, ViewFieldPosition.N, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.Team, location.Direction);
DrawSquare(batch, pov, ViewFieldPosition.O, location.Direction);
#endregion
// Clear the spritebatch
batch.End();
Display.PopScissor();
batch.Begin();
}
示例10: OnDraw
protected override void OnDraw(SpriteBatch sb) {
Color c = new Color(color.R,color.G,color.B,(byte)(alpha*255));
float size = (float)(this.size+(maxSinSize*this.size*Math.Sin(sinSize*Math.PI/180)));
if (chaos) {
sb.End();
sb.Begin(SpriteSortMode.Immediate,bsSubtract);
c = new Color(255,255,255);
if (addLight) size *= 3f;
sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),new Color(c.R,c.G,c.B,(byte)(c.A/2f)),(float)(rot1*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size),SpriteEffects.None,0f);
sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),c,(float)(rot2*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size/2f),SpriteEffects.None,0f);
if (addLight) size /= 3f;
sb.End();
sb.Begin(SpriteSortMode.Immediate,BlendState.Additive);
if (addLight) Lighting.addLight((int)Math.Round(pos.X/16f),(int)Math.Round(pos.Y/16f),c.R/255f*size/32f*c.A/255f/3f,c.G/255f*size/32f*c.A/255f/3f,c.B/255f*size/32f*c.A/255f/3f);
} else {
sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),new Color(c.R,c.G,c.B,(byte)(c.A/2f)),(float)(rot1*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size),SpriteEffects.None,0f);
sb.Draw(ptSquare,pos-Main.screenPosition,GetRectSquare(),c,(float)(rot2*Math.PI/180f),GetCenterSquare(),GetScaleSquare(size/2f),SpriteEffects.None,0f);
if (addLight) Lighting.addLight((int)Math.Round(pos.X/16f),(int)Math.Round(pos.Y/16f),c.R/255f*size/32f*c.A/255f,c.G/255f*size/32f*c.A/255f,c.B/255f*size/32f*c.A/255f);
}
}
示例11: Draw
public static void Draw(SpriteBatch sb) {
if (!visible) return;
if (Config.tileInterface != null || Config.npcInterface != null || Main.npcShop != 0 || Main.signBubble || (Main.npcChatText != null && Main.npcChatText != "")) {
Toggle();
return;
}
sb.End();
int guiX = 80, guiY = 120, guiW = Main.screenWidth-guiX*2, guiH = Main.screenHeight-guiY*2-40;
sb.Begin(SpriteSortMode.Immediate,BlendState.AlphaBlend,null,null,_rasterizerState);
sb.GraphicsDevice.ScissorRectangle = new Rectangle(guiX,guiY,guiW+1,guiH);
int yStart = guiY-scroll, yy = yStart;
for (int i = 0; i < categories.Count; i++) categories[i].Draw(sb,guiX,ref yy,guiW-32);
for (int i = 0; i < achievements.Count; i++) achievements[i].Draw(sb,guiX,ref yy,guiW-32);
sb.End();
sb.Begin(SpriteSortMode.Immediate,BlendState.NonPremultiplied);
int hMax = yy-yStart, scrollMax = hMax-guiH;
if (scrollMax < 0) scrollMax = 0;
if (scroll < 0) scroll = 0;
if (scroll > scrollMax) scroll = scrollMax;
float sliderY = scrollMax == 0 ? 0f : 1f*scroll/scrollMax, sliderH = scrollMax == 0 ? 1f : 1f*guiH/hMax;
Rectangle rectBlack = new Rectangle(guiX+guiW-24,guiY,24,guiH); sb.Draw(whiteTex,rectBlack,new Color(1f,1f,1f,.75f));
Rectangle rectWhite = new Rectangle(guiX+guiW-22,(int)(guiY+2+(guiH-4-(guiH-4)*sliderH)*sliderY),20,(int)((guiH-4)*sliderH)); sb.Draw(whiteTex,rectWhite,new Color(0f,0f,0f,.75f));
if (scrollDragY == -1) {
if (Main.mouseLeft && Main.mouseLeftRelease) {
if (MouseIn(rectBlack)) {
if (MouseIn(rectWhite)) scrollDragY = Main.mouseY-rectWhite.Y; else {
scrollDragY = rectWhite.Height/2;
scroll = (int)(1f*(Main.mouseY-scrollDragY-(guiY+2))/(guiH-4)*hMax);
}
}
}
} else {
scroll = (int)(1f*(Main.mouseY-scrollDragY-(guiY+2))/(guiH-4)*hMax);
if (!Main.mouseLeft) scrollDragY = -1;
}
if (setScroll >= 0) {
scroll = setScroll;
setScroll = -1;
}
stateOld = state;
state = Microsoft.Xna.Framework.Input.Mouse.GetState();
if (stateOld.HasValue && state.HasValue) {
int mouseScrollDiff = (state.Value.ScrollWheelValue-stateOld.Value.ScrollWheelValue)/120;
scroll -= mouseScrollDiff*56;
Main.player[Main.myPlayer].selectedItem += mouseScrollDiff;
while (Main.player[Main.myPlayer].selectedItem < 0) Main.player[Main.myPlayer].selectedItem += 10;
while (Main.player[Main.myPlayer].selectedItem > 9) Main.player[Main.myPlayer].selectedItem -= 10;
}
if (scroll < 0) scroll = 0;
if (scroll > scrollMax) scroll = scrollMax;
int acAchieved = 0, acTotal = 0, acHidden = 0, acLocked = 0, acPoints = 0, acPointsTotal = 0;
UpdateCounters(ref acAchieved,ref acTotal,ref acHidden,ref acLocked,ref acPoints,ref acPointsTotal);
ModWorld.DrawStringShadowed(sb,Main.fontMouseText,"Achieved: "+acAchieved+"/"+acTotal+(acHidden+acLocked != 0 ? " ("+(acHidden > 0 ? "+"+acHidden+" hidden" : "")+(acLocked > 0 ? (acHidden > 0 ? ", " : "")+"+"+acLocked+" locked" : "")+")" : ""),new Vector2(guiX,guiY+guiH+10),Color.White,Color.Black);
ModWorld.DrawStringShadowed(sb,Main.fontMouseText,"Total points: "+acPoints+"/"+acPointsTotal,new Vector2(guiX+guiW-Main.fontMouseText.MeasureString("Total points: "+acPoints+"/"+acPointsTotal).X,guiY+guiH+10),Color.White,Color.Black);
}