C# Класс 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.
Наследование: IInteractable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
matchToTextureDimensions ( ) : void
resetAnimation ( ) : void
setAnimationTime ( float time ) : void
setFrameColumn ( int col ) : void
setFrameRow ( int row ) : void
setImageColumns ( int cols ) : void
setImageRows ( int rows ) : void

Приватные методы

Метод Описание
nullCheck ( ) : void
searchDirectories ( ContentManager content, string fileName ) : Texture2D

Описание методов

Sprite() публичный Метод

Initializes a Sprite at the origin which will match the dimensions of its texture when the texture is loaded
public Sprite ( ) : System
Результат System

Sprite() публичный Метод

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
Результат System

Sprite() публичный Метод

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
Результат System

draw() публичный Метод

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
Результат void

getAnimationTime() публичный Метод

public getAnimationTime ( ) : float
Результат float

getBoundingRect() публичный Метод

public getBoundingRect ( ) : Rectangle
Результат Rectangle

getColor() публичный Метод

public getColor ( ) : Color
Результат Color

getCommonImage() публичный статический Метод

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
Результат Texture2D

getHeight() публичный Метод

public getHeight ( ) : int
Результат int

getImage() публичный Метод

public getImage ( ) : Texture2D
Результат Texture2D

getImageColumns() публичный Метод

public getImageColumns ( ) : int
Результат int

getImageRows() публичный Метод

public getImageRows ( ) : int
Результат int

getWidth() публичный Метод

public getWidth ( ) : int
Результат int

getX() публичный Метод

public getX ( ) : int
Результат int

getXCenter() публичный Метод

public getXCenter ( ) : int
Результат int

getY() публичный Метод

public getY ( ) : int
Результат int

getYCenter() публичный Метод

public getYCenter ( ) : int
Результат int

isVisible() публичный Метод

public isVisible ( ) : bool
Результат bool

loadCommonImage() публичный статический Метод

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
Результат void

loadContent() публичный Метод

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
Результат void

loadImage() публичный Метод

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
Результат void

loadImage() публичный Метод

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
Результат void

matchToTextureDimensions() защищенный Метод

protected matchToTextureDimensions ( ) : void
Результат void

onCollide() публичный Метод

public onCollide ( IInteractable other ) : void
other IInteractable
Результат void

onInteract() публичный Метод

public onInteract ( ) : void
Результат void

reset() публичный Метод

public reset ( ) : void
Результат void

resetAnimation() защищенный Метод

protected resetAnimation ( ) : void
Результат void

setAnimationTime() защищенный Метод

protected setAnimationTime ( float time ) : void
time float
Результат void

setCenter() публичный Метод

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
Результат void

setColor() публичный Метод

public setColor ( Color color ) : void
color Color
Результат void

setDimensions() публичный Метод

Sets the dimensions of this Sprite
public setDimensions ( int width, int height ) : void
width int Width in pixels
height int Height in pixels
Результат void

setFrameColumn() защищенный Метод

protected setFrameColumn ( int col ) : void
col int
Результат void

setFrameRow() защищенный Метод

protected setFrameRow ( int row ) : void
row int
Результат void

setHeight() публичный Метод

public setHeight ( int height ) : void
height int
Результат void

setImage() публичный Метод

Sets a static 2D texture that has already been loaded to be used to draw this Sprite
public setImage ( Texture2D image ) : void
image Texture2D
Результат void

setImage() публичный Метод

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
Результат void

setImageColumns() защищенный Метод

protected setImageColumns ( int cols ) : void
cols int
Результат void

setImageRows() защищенный Метод

protected setImageRows ( int rows ) : void
rows int
Результат void

setPosition() публичный Метод

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
Результат void

setSourceRect() публичный Метод

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
Результат void

setVisible() публичный Метод

public setVisible ( bool visible ) : void
visible bool
Результат void

setWidth() публичный Метод

public setWidth ( int width ) : void
width int
Результат void

setX() публичный Метод

public setX ( int x ) : void
x int
Результат void

setXCenter() публичный Метод

public setXCenter ( int x ) : void
x int
Результат void

setY() публичный Метод

public setY ( int y ) : void
y int
Результат void

setYCenter() публичный Метод

public setYCenter ( int y ) : void
y int
Результат void

unloadCommonImages() публичный статический Метод

Clears memory of all loaded textures. Be sure to call unload on the ContentManager as well.
public static unloadCommonImages ( ) : void
Результат void

update() публичный Метод

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
Результат void