...(avec [ et ] à la place de < et >
public float PositionX { get { return position.X; } set { position.X = value; } } public float PositionY { get { return position.Y; } set { position.Y = value; } }
if (ServiceHelper.Get().IsKeyDown(Keys.Right)) sprite.PositionX += gameTime.ElapsedGameTime.Milliseconds / 10; if (ServiceHelper.Get().IsKeyDown(Keys.Left)) sprite.PositionX -= gameTime.ElapsedGameTime.Milliseconds / 10;
set { sourceRectangle = value; int X = sourceRectangle.X; int Y = sourceRectangle.Y; int width = sourceRectangle.Width; int height = sourceRectangle.Height; int texWidth = texture.Width; int texHeight = texture.Height; if(X + width > texWidth) sourceRectangle.X = texWidth - width; if(Y + height > texHeight) sourceRectangle.Y = texHeight - height; }
using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace Scrolling { public class Sprite { Vector2 position; Texture2D texture; Rectangle destinationRectangle; Rectangle? sourceRectangle; public Vector2 Position { get { return position; } set { position = value; } } public Rectangle? SourceRectangle { get { return sourceRectangle = new Rectangle(0, 0, 200, 300); } set { sourceRectangle = value; int X = sourceRectangle.X;// ici le x n'est pas reconnue int Y = sourceRectangle.Y;// ici le y int width = sourceRectangle.Width;//ici le width int height = sourceRectangle.Height;//et ici le height int texWidth = texture.Width; int texHeight = texture.Height; if (X + width > texWidth) sourceRectangle.X = texWidth - width; if (Y + height > texHeight) sourceRectangle.Y = texHeight - height; } } public Sprite(Vector2 position) { this.position = position; } public Sprite(Vector2 position, Rectangle? sourceRectangle) { this.position = position; this.sourceRectangle = sourceRectangle; } public Sprite(float x, float y, Texture2D texture, Rectangle? sourceRectangle) { this.position = new Vector2(x, y); this.texture = texture; this.sourceRectangle = sourceRectangle; } public void LoadContent(ContentManager content, string assetName) { texture = content.Load<Texture2D>(assetName); } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, position, sourceRectangle, Color.White); } public Sprite(Rectangle destinationRectangle, Rectangle? sourcerectangle) { this.destinationRectangle = destinationRectangle; this.sourceRectangle = sourcerectangle; } public float PositionX { get { return position.X; } set { position.X = value; } } public float PositionY { get { return position.Y; } set { position.Y = value; } } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionset { sourceRectangle = value; if(sourceRectangle.HasValue) { int X = sourceRectangle.X;// ici le x n'est pas reconnue int Y = sourceRectangle.Y;// ici le y int width = sourceRectangle.Width;//ici le width int height = sourceRectangle.Height;//et ici le height int texWidth = texture.Width; int texHeight = texture.Height; if (X + width > texWidth) sourceRectangle = new Rectangle(texWidth - width, sourceRectangle.Value.Y, sourceRectangle.Value.Width, sourceRectangle.Value.Height); if (Y + height > texHeight) sourceRectangle = new Rectangle(sourceRectangle.Value.X, texHeight - height, sourceRectangle.Value.Width, sourceRectangle.Value.Height); } }