本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Sprite类的典型用法代码示例。如果您正苦于以下问题:C# Sprite类的具体用法?C# Sprite怎么用?C# Sprite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sprite类属于Microsoft.Xna.Framework.Graphics命名空间,在下文中一共展示了Sprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainMenu
//Gets info from game and menu items.
//public MainMenu(SpriteFont spriteFont, string[] menuItems)
public MainMenu(SpriteFont spriteFont)
{
this.spriteFont = spriteFont;
//this.menuItems = menuItems;
Input.Initialize();
fontColor = Color.White;
//MeasureMenu();
LoadContent();
logo = new Sprite("logo");
logo.Scale = 0.4f;
logo.Position = new Vector2(Stuff.Resolution.X * 0.675f, Stuff.Resolution.Y * 0.3f);
buttons = new List<Button>();
//start game
Button b = new Button("Buttons", new Vector2(150, 50), new Rectangle(0, 120 * 2, 250, 120), false, false);
buttons.Add(b);
//high scores
b = new Button("Buttons", new Vector2(150, 170), new Rectangle(0, 120 * 4, 250, 120), false, false);
buttons.Add(b);
//settings
b = new Button("Buttons", new Vector2(150, 290), new Rectangle(0, 120 * 5, 250, 120), false, false);
buttons.Add(b);
//exit game
b = new Button("Buttons", new Vector2(150, 410), new Rectangle(0, 120 * 7, 250, 120), false, false);
buttons.Add(b);
menuEgg = new MenuEgg();
}
示例2: Slot_old
public Slot_old(Game game)
: base(game)
{
img = new Sprite(game, GraphicsCollection.GetPack("steag"));
img.StackOrder = 6;
AddChild(img);
}
示例3: AttachAnimation
public void AttachAnimation(Sprite sprite, Animation animation, params ActiveAnimationSetUpdater[] animationUpdaters)
{
animation.Initialize(this, sprite);
foreach (var animationUpdater in animationUpdaters)
{
animationUpdater.Add(animation);
}
Animation activeAnimation = sprite.ActiveAnimation;
if (activeAnimation == null)
{
sprite.ActiveAnimation = animation;
this.animations.Add(animation);
}
else
{
while (activeAnimation.NextAnimation != null)
{
activeAnimation = activeAnimation.NextAnimation;
if (activeAnimation == animation)
throw new ArgumentException("Same animation attached more than once");
}
activeAnimation.NextAnimation = animation;
}
}
示例4: Reticle
public Reticle(Texture2D tex, SpriteBatch sb, Vector2 pos)
{
this._sprite = new Sprite(tex, sb, pos);
this._mouseState = Mouse.GetState();
this._position.X = this._mouseState.Position.X;
this._position.Y = this._mouseState.Position.Y;
}
示例5: CreateCursor
/// <summary>
/// Instantiates the cursor.
/// Sets the cursor's layer.
/// Offsets the cursor to be centered on it's position.
/// </summary>
private void CreateCursor()
{
_cursor = new Sprite(Content.Load<Texture2D>("cursor"), Vector2.Zero);
_cursor.Layer = 1.0f;
_cursor.SetOffset(Anchor.Center);
Drawables.Add(_cursor);
}
示例6: Draw
public override void Draw(GameTime gameTime)
{
//TODO: Handle rotation??
//TODO: Keep only one sprite and change it, do not recreate one
Sprite s = new Sprite(Texture, RectangleToRender, Color, Layer)
{
Rotation = GameObject.Transform.Rotation,
Color = Color,
Origin = Origin,
Scale = GameObject.Transform.Scale
};
Engine.SpriteRenderer.Draw(s);
//if (Texture != null)
//spriteBatch.Draw(
// Texture,
// RectangleToRender,
// null,
// Color,
// 0,
// //new Vector2((float)RectangleToRender.Width / 2, (float)RectangleToRender.Height / 2),//TODO: Why is the Origin acting so weird?
// Vector2.Zero,
// SpriteEffects.None,
// 0);
}
示例7: MainScene
public MainScene(ContentManager content, GraphicsDeviceManager graphicsManager)
{
Stuff.Initialize(content, graphicsManager);
graphics = graphicsManager;
onScreenMessages = new OnScreenMessages();
Camera2d.Position = Stuff.ScreenCenter;
input = new Input();
characters = new List<Character>();
player = new Player(characters);
debugTiles = new List<Sprite>();
for (int i = -10; i < 30; i++)
{
Sprite s = new Sprite("SpriteSheet");
s.Source = new Rectangle(1 * 150, 9 * 150, 150, 150);
s.Position = new Vector2(i * 150, 400);
debugTiles.Add(s);
}
for (int i = 0; i < 100; i++)
{
Sprite tempSprite = new Sprite("SpriteSheet");
tempSprite.Source = new Rectangle(11 * 150, 9 * 150, 150, 150);
tempSprite.Position = new Vector2(150*i, 250 + (-150*i));
debugTiles.Add(tempSprite);
}
}
示例8: GraphBar
public GraphBar(Game game, int percent)
: base(game)
{
visual = new Sprite(game, GraphicsCollection.GetPack("pixel"));
Percent = percent;
AddChild(visual);
}
示例9: MoveableTile
/// <summary>
/// Creates a new Moveable tile.
/// </summary>
/// <param name="sprite">Sprite representing texture, size, and position of the tile. </param>
/// <param name="collision">Type of collision for the tile.</param>
/// <param name="velocity">Tile velocity: .X is the movement angle in radians and .Y is the speed in pixels per second.</param>
public MoveableTile(Sprite sprite, TileCollision collision, Vector2 velocity)
: base(sprite, collision)
{
this.velocity = velocity;
Leader = this; // By default, tiles lead themselves
}
示例10: CombatTextureHolder
/// <summary>
/// Creates the CombatTextureHolder's arrays, and all the members in them.
/// </summary>
/// <param name="manager">Main game class's Content Loader.</param>
protected CombatTextureHolder(GraphicsDevice graphics)
{
int numAbilities = ConstantHolder.textureLoader.getTexturesByType((int)TextureTypes.Ability).Count;
int numAbilityEffects = ConstantHolder.textureLoader.getTexturesByType((int)TextureTypes.AbilityEffect).Count;
abilityButtonSprites = new Sprite[numAbilities];
abilityAnimationSprites = new Sprite[numAbilities];
abilityEffectSprites = new Sprite[numAbilityEffects];
abilityImpactSprites = new Sprite[numAbilities];
effectIconSprites = new Sprite[numAbilityEffects];
int abilityIndex = 0;
foreach (TextureXML tex in ConstantHolder.textureLoader.textureCategories[(int)TextureTypes.Ability])
{
ConstantHolder.AbilityButtonDict.Add(tex.fileName, abilityIndex);
//For abilities, portrait = impact
loadAbilityAnimation(graphics, abilityIndex++, tex.fileName, tex.mainSize.vec, tex.ColumnHeights,
tex.portraitName, tex.portraitSize.vec, tex.PortraitColumnHeights,
tex.buttonName, tex.buttonSize.vec, tex.ButtonColumnHeights);
}
int effectIndex = 0;
foreach (TextureXML tex in ConstantHolder.textureLoader.textureCategories[(int)TextureTypes.AbilityEffect])
{
ConstantHolder.AbilityEffectSpriteDict.Add(tex.fileName, effectIndex);
loadEffect(graphics, effectIndex++, tex.fileName, tex.mainSize.vec, tex.ColumnHeights,
tex.iconName, tex.iconSize.vec, tex.IconColumnHeights);
}
}
示例11: Update
//check for colisions
public void Update(List<Sprite> collisionArray)
{
for (int x = 0; x < collisionArray.Count; ++x)
{
//where the sprite collisions happened
Collided_Bottom = null;
Collided_Top = null;
Collided_Left = null;
Collided_Right = null;
for (int y = 0; y < collisionArray.Count; ++y)
{
//check if it contains the bottom center
//If bottom left overlaps check if it is more bottom or more left
if (x !=y && collisionArray[x].HitBox.Intersects(collisionArray[y].HitBox))
{
//CollisionArray returns 0 when the objects should collide normally, 1 if it should ignore collisions
//Check if the mid points of figure y touch figure x
if (collisionArray[y].HitBox.Contains((int)(collisionArray[x].HitBox.X + collisionArray[x].HitBox.Width / 2), (int)(collisionArray[x].HitBox.Y + collisionArray[x].HitBox.Height)) && collisionArray[y].HitBox.Y > collisionArray[x].HitBox.Y)
Collided_Bottom = collisionArray[y];
if (collisionArray[y].HitBox.Contains((int)(collisionArray[x].HitBox.X + collisionArray[x].HitBox.Width / 2), (int)(collisionArray[x].HitBox.Y)) && collisionArray[x].HitBox.Y > collisionArray[y].HitBox.Y)
Collided_Top = collisionArray[y];
if (collisionArray[y].HitBox.Contains((int)(collisionArray[x].HitBox.X), (int)(collisionArray[x].HitBox.Y + collisionArray[x].HitBox.Height / 2)) && collisionArray[y].HitBox.X < collisionArray[x].HitBox.X)
Collided_Left = collisionArray[y];
if (collisionArray[y].HitBox.Contains((int)collisionArray[x].HitBox.X + collisionArray[x].HitBox.Width, (int)collisionArray[x].HitBox.Y + collisionArray[x].HitBox.Height / 2) && collisionArray[x].HitBox.X < collisionArray[y].HitBox.X)
Collided_Right = collisionArray[y];
//Adjusts the location of the collisionArray so that they are no longer colliding and changes their velocity
AdjustPosition(collisionArray, x);
}
}
}
}
示例12: Mask
public Mask(Sprite spriteMask, Sprite spriteTarget)
{
_spriteMask = spriteMask;
_spriteTarget = spriteTarget;
Render.Viewport.ResolutionChanged += Setup;
Setup();
_maskStencilState = new DepthStencilState
{
StencilEnable = true,
StencilFunction = CompareFunction.Always,
StencilPass = StencilOperation.Replace,
ReferenceStencil = 1,
DepthBufferEnable = false,
};
_targetStencilState = new DepthStencilState
{
StencilEnable = true,
StencilFunction = CompareFunction.LessEqual,
StencilPass = StencilOperation.Replace,
ReferenceStencil = 1,
DepthBufferEnable = false,
};
Add(new DrawComponent(Draw));
}
示例13: Actor
public Actor(Vector2 position, Vector2 size, Sprite sprite)
{
Position = position;
Size = size;
Sprite = sprite;
facingLeft = false;
}
示例14: BrainMapManager
//private BrainMapMarker currentMapMarker = null;
public BrainMapManager(SpriteBatch spriteBatch, Soul game, AudioManager audioManager, InputManager controls, Vector2 position)
{
this.audioManager = audioManager;
bg = new Sprite(spriteBatch, game, Constants.BRAIN_MAP_BG);
mapList = new List<BrainMapMarker>();
List<BrainMapMarker> tmpList = new List<BrainMapMarker>();
/*mapList.Add(tmpList);
tmpList = new List<BrainMapMarker>();
mapList.Add(tmpList);
tmpList = new List<BrainMapMarker>();
mapList.Add(tmpList);*/
menuManager = new MenuManager(controls);
ImageButton button = new ImageButton(spriteBatch, game, controls, new Vector2((float)Constants.RESOLUTION_VIRTUAL_WIDTH * 0.5f - 150, (float)Constants.RESOLUTION_VIRTUAL_HEIGHT * 0.5f + 200), Constants.GUI_CLEANSE, "cleanse");
button.onClick += new ImageButton.ButtonEventHandler(OnButtonPress);
menuManager.AddButton(button);
button = new ImageButton(spriteBatch, game, controls, new Vector2((float)Constants.RESOLUTION_VIRTUAL_WIDTH * 0.5f + 150, (float)Constants.RESOLUTION_VIRTUAL_HEIGHT * 0.5f + 200), Constants.GUI_BACK, "back");
button.onClick += new ImageButton.ButtonEventHandler(OnButtonPress);
menuManager.AddButton(button);
menuManager.initialize();
fadeinOut = new FadeInOut(spriteBatch, game, 100);
this.position = position;
offset = new Vector2((float)bg.X * 0.5f, (float)bg.Y *0.5f);
this.controls = controls;
}
示例15: Goomba
public Goomba(Vector2 initialPosition)
: base(initialPosition)
{
death = new Sprite(Textures.GetTexture(Textures.Texture.goomba), new Rectangle(16, 0 + (16 * World.WorldType), 16, 16));
goomba = new Sprite(Textures.GetTexture(Textures.Texture.goomba), new Rectangle(0, 0 + (16 * World.WorldType), 16, 16));
velocity.X = -walkingSpeed;
}