Barotrauma Client Doc
Barotrauma.Sprite Class Reference
Inheritance diagram for Barotrauma.Sprite:
Barotrauma.SpriteSheet Barotrauma.SpriteSheet

Public Member Functions

override string ToString ()
 
 Sprite (ContentXElement element, string path="", string file="", bool lazyLoad=false)
 
 Sprite (string newFile, Vector2 newOrigin)
 
 Sprite (string newFile, Rectangle? sourceRectangle, Vector2? origin=null, float rotation=0)
 
void Remove ()
 
void ReloadXML ()
 Works only if there is a name attribute defined for the sprite. For items and structures, the entity id or name is used if the sprite's name attribute is not defined. More...
 
bool ParseTexturePath (string path="", string file="")
 
 Sprite (Sprite other)
 
 Sprite (Texture2D texture, Rectangle? sourceRectangle, Vector2? newOffset, float newRotation=0.0f, string path=null)
 
async Task LazyLoadAsync ()
 
void EnsureLazyLoaded (bool isAsync=false)
 
void ReloadTexture ()
 
void Draw (ISpriteBatch spriteBatch, Vector2 pos, float rotate=0.0f, float scale=1.0f, SpriteEffects spriteEffect=SpriteEffects.None)
 
void Draw (ISpriteBatch spriteBatch, Vector2 pos, Color color, float rotate=0.0f, float scale=1.0f, SpriteEffects spriteEffect=SpriteEffects.None, float? depth=null)
 
void Draw (ISpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate=0.0f, float scale=1.0f, SpriteEffects spriteEffect=SpriteEffects.None, float? depth=null)
 
virtual void Draw (ISpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect=SpriteEffects.None, float? depth=null)
 
void DrawSilhouette (SpriteBatch spriteBatch, Vector2 pos, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect=SpriteEffects.None, float? depth=null)
 Creates a silhouette for the sprite (or outline if the sprite is rendered on top of it) More...
 
void DrawTiled (ISpriteBatch spriteBatch, Vector2 position, Vector2 targetSize, float rotation=0f, Vector2? origin=null, Color? color=null, Vector2? startOffset=null, Vector2? textureScale=null, float? depth=null, SpriteEffects? spriteEffects=null)
 

Static Public Member Functions

static Identifier GetIdentifier (XElement sourceElement)
 Creates a supposedly unique identifier from the parent element. If the parent element is not found, uses the sprite element. TODO: If there are multiple elements with exactly the same data, the ids will fail. -> Is there a better way to identify the sprites? ALSO TODO: delete :) More...
 
static Texture2D LoadTexture (string file, bool compress=true, ContentPackage contentPackage=null)
 

Public Attributes

Vector2 size = Vector2.One
 
float rotation
 
SpriteEffects effects = SpriteEffects.None
 

Static Public Attributes

static readonly Version LastBrokenTiledSpriteGameVersion = new Version(major: 1, minor: 2, build: 7, revision: 0)
 Last version of the game that had broken handling of sprites that were scaled, flipped and offset More...
 

Protected Attributes

Vector2 offset
 
Vector2 origin
 
float depth
 
volatile bool loadingAsync = false
 

Properties

ContentXElement SourceElement [get]
 Reference to the xml element from where the sprite was created. Can be null if the sprite was not defined in xml! More...
 
bool LazyLoad [get]
 
Rectangle SourceRect [get, set]
 
float Depth [get, set]
 
Vector2 Origin [get, set]
 In pixels More...
 
Vector2 RelativeOrigin [get, set]
 0 - 1 More...
 
Vector2 RelativeSize [get]
 
ContentPath FilePath [get]
 
string FullPath [get]
 
bool Compress [get]
 
Identifier EntityIdentifier [get, set]
 Identifier of the Map Entity so that we can link the sprite to its owner. More...
 
string Name [get, set]
 
Identifier Identifier [get]
 
static IEnumerable< SpriteLoadedSprites [get]
 
Texture2D texture [get]
 
Texture2D Texture [get]
 
bool Loaded [get]
 

Detailed Description

Constructor & Destructor Documentation

◆ Sprite() [1/5]

Barotrauma.Sprite.Sprite ( ContentXElement  element,
string  path = "",
string  file = "",
bool  lazyLoad = false 
)

◆ Sprite() [2/5]

Barotrauma.Sprite.Sprite ( string  newFile,
Vector2  newOrigin 
)

◆ Sprite() [3/5]

Barotrauma.Sprite.Sprite ( string  newFile,
Rectangle?  sourceRectangle,
Vector2?  origin = null,
float  rotation = 0 
)

◆ Sprite() [4/5]

Barotrauma.Sprite.Sprite ( Sprite  other)

◆ Sprite() [5/5]

Barotrauma.Sprite.Sprite ( Texture2D  texture,
Rectangle?  sourceRectangle,
Vector2?  newOffset,
float  newRotation = 0.0f,
string  path = null 
)

Member Function Documentation

◆ Draw() [1/4]

void Barotrauma.Sprite.Draw ( ISpriteBatch  spriteBatch,
Vector2  pos,
Color  color,
float  rotate = 0.0f,
float  scale = 1.0f,
SpriteEffects  spriteEffect = SpriteEffects.None,
float?  depth = null 
)

◆ Draw() [2/4]

virtual void Barotrauma.Sprite.Draw ( ISpriteBatch  spriteBatch,
Vector2  pos,
Color  color,
Vector2  origin,
float  rotate,
Vector2  scale,
SpriteEffects  spriteEffect = SpriteEffects.None,
float?  depth = null 
)
virtual

Reimplemented in Barotrauma.SpriteSheet.

Definition at line 265 of file BarotraumaClient/ClientSource/Sprite/Sprite.cs.

◆ Draw() [3/4]

void Barotrauma.Sprite.Draw ( ISpriteBatch  spriteBatch,
Vector2  pos,
Color  color,
Vector2  origin,
float  rotate = 0.0f,
float  scale = 1.0f,
SpriteEffects  spriteEffect = SpriteEffects.None,
float?  depth = null 
)

◆ Draw() [4/4]

void Barotrauma.Sprite.Draw ( ISpriteBatch  spriteBatch,
Vector2  pos,
float  rotate = 0.0f,
float  scale = 1.0f,
SpriteEffects  spriteEffect = SpriteEffects.None 
)

◆ DrawSilhouette()

void Barotrauma.Sprite.DrawSilhouette ( SpriteBatch  spriteBatch,
Vector2  pos,
Vector2  origin,
float  rotate,
Vector2  scale,
SpriteEffects  spriteEffect = SpriteEffects.None,
float?  depth = null 
)

Creates a silhouette for the sprite (or outline if the sprite is rendered on top of it)

Definition at line 275 of file BarotraumaClient/ClientSource/Sprite/Sprite.cs.

◆ DrawTiled()

void Barotrauma.Sprite.DrawTiled ( ISpriteBatch  spriteBatch,
Vector2  position,
Vector2  targetSize,
float  rotation = 0f,
Vector2?  origin = null,
Color?  color = null,
Vector2?  startOffset = null,
Vector2?  textureScale = null,
float?  depth = null,
SpriteEffects?  spriteEffects = null 
)

◆ EnsureLazyLoaded()

void Barotrauma.Sprite.EnsureLazyLoaded ( bool  isAsync = false)

◆ GetIdentifier()

static Identifier Barotrauma.Sprite.GetIdentifier ( XElement  sourceElement)
static

Creates a supposedly unique identifier from the parent element. If the parent element is not found, uses the sprite element. TODO: If there are multiple elements with exactly the same data, the ids will fail. -> Is there a better way to identify the sprites? ALSO TODO: delete :)

Definition at line 206 of file BarotraumaShared/SharedSource/Sprite/Sprite.cs.

◆ LazyLoadAsync()

async Task Barotrauma.Sprite.LazyLoadAsync ( )

◆ LoadTexture()

static Texture2D Barotrauma.Sprite.LoadTexture ( string  file,
bool  compress = true,
ContentPackage  contentPackage = null 
)
static

◆ ParseTexturePath()

bool Barotrauma.Sprite.ParseTexturePath ( string  path = "",
string  file = "" 
)

◆ ReloadTexture()

void Barotrauma.Sprite.ReloadTexture ( )

◆ ReloadXML()

void Barotrauma.Sprite.ReloadXML ( )

Works only if there is a name attribute defined for the sprite. For items and structures, the entity id or name is used if the sprite's name attribute is not defined.

Definition at line 231 of file BarotraumaShared/SharedSource/Sprite/Sprite.cs.

◆ Remove()

void Barotrauma.Sprite.Remove ( )

◆ ToString()

override string Barotrauma.Sprite.ToString ( )

Member Data Documentation

◆ depth

float Barotrauma.Sprite.depth
protected

◆ effects

SpriteEffects Barotrauma.Sprite.effects = SpriteEffects.None

◆ LastBrokenTiledSpriteGameVersion

readonly Version Barotrauma.Sprite.LastBrokenTiledSpriteGameVersion = new Version(major: 1, minor: 2, build: 7, revision: 0)
static

Last version of the game that had broken handling of sprites that were scaled, flipped and offset

Definition at line 290 of file BarotraumaClient/ClientSource/Sprite/Sprite.cs.

◆ loadingAsync

volatile bool Barotrauma.Sprite.loadingAsync = false
protected

◆ offset

Vector2 Barotrauma.Sprite.offset
protected

◆ origin

Vector2 Barotrauma.Sprite.origin
protected

◆ rotation

float Barotrauma.Sprite.rotation

◆ size

Vector2 Barotrauma.Sprite.size = Vector2.One

Property Documentation

◆ Compress

bool Barotrauma.Sprite.Compress
get

◆ Depth

float Barotrauma.Sprite.Depth
getset

◆ EntityIdentifier

Identifier Barotrauma.Sprite.EntityIdentifier
getset

Identifier of the Map Entity so that we can link the sprite to its owner.

Definition at line 101 of file BarotraumaShared/SharedSource/Sprite/Sprite.cs.

◆ FilePath

ContentPath Barotrauma.Sprite.FilePath
get

◆ FullPath

string Barotrauma.Sprite.FullPath
get

◆ Identifier

Identifier Barotrauma.Sprite.Identifier
get

◆ LazyLoad

bool Barotrauma.Sprite.LazyLoad
get

◆ Loaded

bool Barotrauma.Sprite.Loaded
get

◆ LoadedSprites

IEnumerable<Sprite> Barotrauma.Sprite.LoadedSprites
staticget

◆ Name

string Barotrauma.Sprite.Name
getset

◆ Origin

Vector2 Barotrauma.Sprite.Origin
getset

In pixels

Definition at line 61 of file BarotraumaShared/SharedSource/Sprite/Sprite.cs.

◆ RelativeOrigin

Vector2 Barotrauma.Sprite.RelativeOrigin
getset

0 - 1

Definition at line 75 of file BarotraumaShared/SharedSource/Sprite/Sprite.cs.

◆ RelativeSize

Vector2 Barotrauma.Sprite.RelativeSize
get

◆ SourceElement

ContentXElement Barotrauma.Sprite.SourceElement
get

Reference to the xml element from where the sprite was created. Can be null if the sprite was not defined in xml!

Definition at line 18 of file BarotraumaShared/SharedSource/Sprite/Sprite.cs.

◆ SourceRect

Rectangle Barotrauma.Sprite.SourceRect
getset

◆ texture

Texture2D Barotrauma.Sprite.texture
getprotected

◆ Texture

Texture2D Barotrauma.Sprite.Texture
get