Documentation
¶
Overview ¶
Package spriteutils provides some utility functions for dealing with 2D sprites on top of the ebiten game library
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SimpleSprite ¶
type SimpleSprite interface { // Update the sprite Update() // Draw the sprite to screen Draw(screen *ebiten.Image) error }
SimpleSprite is a sprite interface with methods to draw and update
type Sprite ¶
type Sprite struct { // Image is the ebiten image to draw for this sprite Image *ebiten.Image // X is the sprites x-axis position in 2D space X int // Y is the sprites y-axis position in 2D space Y int // XVelocity is the sprite's velocity in the x-axis XVelocity float64 // YVelocity is the sprite's velocity in the y-axis YVelocity float64 // Rotation is the sprite's rotation in radians Rotation float64 }
Sprite represents an image with position, rotation, and velocity
func (*Sprite) ApplyImpulse ¶
ApplyImpulse applies a 2d vector force represented by (xVelocity, yVelocity) to the sprite
func (*Sprite) Draw ¶
Draw the sprite to screen after applying rotation and translation transformations
func (*Sprite) IsColliding ¶
IsColliding determines whether there is a collision between this sprite and another. A collision is determined to have occurred if the non-transparent sprite images are touching
type SpriteFactory ¶
type SpriteFactory struct { // Images represent the possible images for the generated sprite. Will be chosen randomly when generating Images []*ebiten.Image // MinX represents the generated sprite's minimum x-axis position in 2D space MinX int // MaxX represents the generated sprite's maximum x-axis position in 2D space MaxX int // MinY represents the generated sprite's minimum y-axis position in 2D space MinY int // MaxY represents the generated sprite's maximum y-axis position in 2D space MaxY int }
SpriteFactory is a helper for creating sprites in random x, y positions
func (*SpriteFactory) GenerateSprite ¶
func (factory *SpriteFactory) GenerateSprite() *Sprite
GenerateSprite generates a sprite using the factories settings
type TransientSprite ¶
type TransientSprite struct { // CreatedAtGameTime is the duration of time that has past since the game started. // We cannot use real time since if the game window is unfocused, it will pause. CreatedAtGameTime time.Duration // LifetimeDuration is the duration of time to keep this sprite alive LifetimeDuration time.Duration // Sprite is the limited lifetime sprite Sprite SimpleSprite // IsExpired represents whether the sprite lifetime has surpassed or not IsExpired bool }
TransientSprite is a sprite that exists for a period of time. Once it is expired it will no longer Draw or Update, but it is up to the user to remove any references so that it is garbage collected
func (*TransientSprite) Draw ¶
func (t *TransientSprite) Draw(screen *ebiten.Image) error
Draw the sprite to screen if it has not expired
func (*TransientSprite) Update ¶
func (t *TransientSprite) Update(currentGameTime time.Duration)
Update the sprite is it has not expired