C# Class SunsetHigh.Sprite

Class for anything that can be drawn with a sprite. Characters and Pickups (and other drawable game components) can extend from this class to add behavior to the sprite. Alternative, just use this class for simple or static drawings.
Inheritance: IInteractable
Afficher le fichier Open project: ErraticUnicorn/MOSH Class Usage Examples

Méthodes publiques

Méthode Description
Sprite ( ) : System

Initializes a Sprite at the origin which will match the dimensions of its texture when the texture is loaded

Sprite ( int x, int y ) : System

Initializes a Sprite at the given position. It will match the dimensions of its texture when the texture is loaded.

Sprite ( int x, int y, int width, int height ) : System

Initializes a Sprite at the given position with the given dimensions

draw ( SpriteBatch sb ) : void

Draws this sprite. Call this method on every Sprite in the Game's draw cycle. Override this method in child classes as necessary (i.e. if drawing additional components)

getAnimationTime ( ) : float
getBoundingRect ( ) : Rectangle
getColor ( ) : Color
getCommonImage ( string imageFileName ) : Texture2D

Retrieves a pre-loaded 2D texture to associate with an instantiated Sprite object. Good for multiple objects using the same texture

getHeight ( ) : int
getImage ( ) : Texture2D
getImageColumns ( ) : int
getImageRows ( ) : int
getWidth ( ) : int
getX ( ) : int
getXCenter ( ) : int
getY ( ) : int
getYCenter ( ) : int
isVisible ( ) : bool
loadCommonImage ( ContentManager content, string imageFileName ) : void

Loads a 2D texture in the "Content" directory for use by multiple Sprite objects. Call this method in the loading content cycle, and when instantiating new objects in-game, call getCommonImage()

loadContent ( ContentManager content ) : void

Loads all content necessary for this Sprite. Call this method on every Sprite in the Game's load cycle. Override this method when writing the classes that must load specific sprites and sound effects.

loadImage ( ContentManager content, string fileName ) : void

Loads a static 2D texture with the given filename in the "Content" directory

loadImage ( ContentManager content, string fileName, int numRows, int numCols, float anTime ) : void

Loads a 2D spritesheet with the given filename in the "Content" directory

onCollide ( IInteractable other ) : void
onInteract ( ) : void
reset ( ) : void
setCenter ( int x, int y ) : void

Sets the position of this Sprite with given center coordinates

setColor ( Color color ) : void
setDimensions ( int width, int height ) : void

Sets the dimensions of this Sprite

setHeight ( int height ) : void
setImage ( Texture2D image ) : void

Sets a static 2D texture that has already been loaded to be used to draw this Sprite

setImage ( Texture2D image, int numRows, int numCols, float anTime ) : void

Sets an animating 2D texture that has already been loaded to be used to draw this Sprite

setPosition ( int x, int y ) : void

Sets the position of this Sprite given the coordinates of its top-left corner

setSourceRect ( int x, int y, int width, int height ) : void

Sets the source rectangle of a loaded texture for this Sprite (if the particular texture is a collection of different sprites).

setVisible ( bool visible ) : void
setWidth ( int width ) : void
setX ( int x ) : void
setXCenter ( int x ) : void
setY ( int y ) : void
setYCenter ( int y ) : void
unloadCommonImages ( ) : void

Clears memory of all loaded textures. Be sure to call unload on the ContentManager as well.

update ( float elapsed ) : void

Updates this sprite based on time. If the sprite can animate, then it will do so here. Call this method on every Sprite in the Game's update cycle. Override this method in child classes as necessary.

Méthodes protégées

Méthode Description
matchToTextureDimensions ( ) : void
resetAnimation ( ) : void
setAnimationTime ( float time ) : void
setFrameColumn ( int col ) : void
setFrameRow ( int row ) : void
setImageColumns ( int cols ) : void
setImageRows ( int rows ) : void

Private Methods

Méthode Description
nullCheck ( ) : void
searchDirectories ( ContentManager content, string fileName ) : Texture2D

Method Details

Sprite() public méthode

Initializes a Sprite at the origin which will match the dimensions of its texture when the texture is loaded
public Sprite ( ) : System
Résultat System

Sprite() public méthode

Initializes a Sprite at the given position. It will match the dimensions of its texture when the texture is loaded.
public Sprite ( int x, int y ) : System
x int X coordinate of top-left corner
y int Y coordinate of top-left corner
Résultat System

Sprite() public méthode

Initializes a Sprite at the given position with the given dimensions
public Sprite ( int x, int y, int width, int height ) : System
x int X coordinate of top-left corner
y int Y coordinate of top-left corner
width int Width in pixels; specify 0 to use texture dimensions
height int Height in pixels; specify 0 to use texture dimensions
Résultat System

draw() public méthode

Draws this sprite. Call this method on every Sprite in the Game's draw cycle. Override this method in child classes as necessary (i.e. if drawing additional components)
public draw ( SpriteBatch sb ) : void
sb Microsoft.Xna.Framework.Graphics.SpriteBatch SpriteBatch passed in through Game
Résultat void

getAnimationTime() public méthode

public getAnimationTime ( ) : float
Résultat float

getBoundingRect() public méthode

public getBoundingRect ( ) : Rectangle
Résultat Rectangle

getColor() public méthode

public getColor ( ) : Color
Résultat Color

getCommonImage() public static méthode

Retrieves a pre-loaded 2D texture to associate with an instantiated Sprite object. Good for multiple objects using the same texture
public static getCommonImage ( string imageFileName ) : Texture2D
imageFileName string The file name of the image that was previously loaded
Résultat Texture2D

getHeight() public méthode

public getHeight ( ) : int
Résultat int

getImage() public méthode

public getImage ( ) : Texture2D
Résultat Texture2D

getImageColumns() public méthode

public getImageColumns ( ) : int
Résultat int

getImageRows() public méthode

public getImageRows ( ) : int
Résultat int

getWidth() public méthode

public getWidth ( ) : int
Résultat int

getX() public méthode

public getX ( ) : int
Résultat int

getXCenter() public méthode

public getXCenter ( ) : int
Résultat int

getY() public méthode

public getY ( ) : int
Résultat int

getYCenter() public méthode

public getYCenter ( ) : int
Résultat int

isVisible() public méthode

public isVisible ( ) : bool
Résultat bool

loadCommonImage() public static méthode

Loads a 2D texture in the "Content" directory for use by multiple Sprite objects. Call this method in the loading content cycle, and when instantiating new objects in-game, call getCommonImage()
public static loadCommonImage ( ContentManager content, string imageFileName ) : void
content ContentManager The content manager
imageFileName string The file name of the image, without the extension
Résultat void

loadContent() public méthode

Loads all content necessary for this Sprite. Call this method on every Sprite in the Game's load cycle. Override this method when writing the classes that must load specific sprites and sound effects.
public loadContent ( ContentManager content ) : void
content ContentManager ContentManager passed in through Game
Résultat void

loadImage() public méthode

Loads a static 2D texture with the given filename in the "Content" directory
public loadImage ( ContentManager content, string fileName ) : void
content ContentManager ContentManager passed in through Game
fileName string File name of XNB image in "Content" directory
Résultat void

loadImage() public méthode

Loads a 2D spritesheet with the given filename in the "Content" directory
public loadImage ( ContentManager content, string fileName, int numRows, int numCols, float anTime ) : void
content ContentManager ContentManager passed in through Game
fileName string File name of XNB image in "Content" directory
numRows int Number of rows in this spritesheet
numCols int Number of columns in this spritesheet
anTime float Time between frames (in seconds) when animating the sprite
Résultat void

matchToTextureDimensions() protected méthode

protected matchToTextureDimensions ( ) : void
Résultat void

onCollide() public méthode

public onCollide ( IInteractable other ) : void
other IInteractable
Résultat void

onInteract() public méthode

public onInteract ( ) : void
Résultat void

reset() public méthode

public reset ( ) : void
Résultat void

resetAnimation() protected méthode

protected resetAnimation ( ) : void
Résultat void

setAnimationTime() protected méthode

protected setAnimationTime ( float time ) : void
time float
Résultat void

setCenter() public méthode

Sets the position of this Sprite with given center coordinates
public setCenter ( int x, int y ) : void
x int X coordinate of center
y int Y coordinate of center
Résultat void

setColor() public méthode

public setColor ( Color color ) : void
color Color
Résultat void

setDimensions() public méthode

Sets the dimensions of this Sprite
public setDimensions ( int width, int height ) : void
width int Width in pixels
height int Height in pixels
Résultat void

setFrameColumn() protected méthode

protected setFrameColumn ( int col ) : void
col int
Résultat void

setFrameRow() protected méthode

protected setFrameRow ( int row ) : void
row int
Résultat void

setHeight() public méthode

public setHeight ( int height ) : void
height int
Résultat void

setImage() public méthode

Sets a static 2D texture that has already been loaded to be used to draw this Sprite
public setImage ( Texture2D image ) : void
image Texture2D
Résultat void

setImage() public méthode

Sets an animating 2D texture that has already been loaded to be used to draw this Sprite
public setImage ( Texture2D image, int numRows, int numCols, float anTime ) : void
image Texture2D The pre-loaded image
numRows int Number of rows in this spritesheet
numCols int Number of columns in this spritesheet
anTime float Time between frames (in seconds) when animating the sprite
Résultat void

setImageColumns() protected méthode

protected setImageColumns ( int cols ) : void
cols int
Résultat void

setImageRows() protected méthode

protected setImageRows ( int rows ) : void
rows int
Résultat void

setPosition() public méthode

Sets the position of this Sprite given the coordinates of its top-left corner
public setPosition ( int x, int y ) : void
x int X coordinate of top-left corner
y int Y coordinate of top-left corner
Résultat void

setSourceRect() public méthode

Sets the source rectangle of a loaded texture for this Sprite (if the particular texture is a collection of different sprites).
public setSourceRect ( int x, int y, int width, int height ) : void
x int X coordinate of top-left corner
y int Y coordinate of top-left corner
width int Width in pixels
height int Height in pixels
Résultat void

setVisible() public méthode

public setVisible ( bool visible ) : void
visible bool
Résultat void

setWidth() public méthode

public setWidth ( int width ) : void
width int
Résultat void

setX() public méthode

public setX ( int x ) : void
x int
Résultat void

setXCenter() public méthode

public setXCenter ( int x ) : void
x int
Résultat void

setY() public méthode

public setY ( int y ) : void
y int
Résultat void

setYCenter() public méthode

public setYCenter ( int y ) : void
y int
Résultat void

unloadCommonImages() public static méthode

Clears memory of all loaded textures. Be sure to call unload on the ContentManager as well.
public static unloadCommonImages ( ) : void
Résultat void

update() public méthode

Updates this sprite based on time. If the sprite can animate, then it will do so here. Call this method on every Sprite in the Game's update cycle. Override this method in child classes as necessary.
public update ( float elapsed ) : void
elapsed float Time (in seconds) that has elapsed since the last update
Résultat void