libscratchcpp
A library for C++ based Scratch project players
Loading...
Searching...
No Matches
libscratchcpp::Sprite Class Reference

The Sprite class represents a Scratch sprite. More...

#include <scratchcpp/sprite.h>

Inheritance diagram for libscratchcpp::Sprite:
Collaboration diagram for libscratchcpp::Sprite:

Public Types

enum class  RotationStyle { AllAround , LeftRight , DoNotRotate }
 

Public Member Functions

 Sprite ()
 
 Sprite (const Sprite &)=delete
 
void setInterface (ISpriteHandler *newInterface)
 
ISpriteHandlergetInterface () const
 
std::shared_ptr< Spriteclone ()
 
void deleteClone ()
 
bool isClone () const
 
SpritecloneSprite () const
 
const std::vector< std::shared_ptr< Sprite > > & clones () const
 
bool visible () const
 
void setVisible (bool newVisible)
 
double x () const
 
void setX (double newX)
 
double y () const
 
void setY (double newY)
 
void setPosition (double x, double y)
 
bool dragging () const
 
void startDragging ()
 
void stopDragging ()
 
void dragToPosition (double x, double y)
 
double size () const
 
void setSize (double newSize)
 
void setCostumeIndex (int newCostumeIndex) override
 
int currentCostumeWidth () const override
 
int currentCostumeHeight () const override
 
double direction () const
 
void setDirection (double newDirection)
 
bool draggable () const
 
void setDraggable (bool newDraggable)
 
RotationStyle rotationStyle () const
 
std::string rotationStyleStr () const
 
void setRotationStyle (RotationStyle newRotationStyle)
 
void setRotationStyle (const std::string &newRotationStyle)
 
void setRotationStyle (const char *newRotationStyle)
 
void setLayerOrder (int newLayerOrder) override
 
Rect boundingRect () const override
 
Rect fastBoundingRect () const override
 
void keepInFence (double newX, double newY, double *fencedX, double *fencedY) const
 
bool touchingPoint (double x, double y) const override
 
bool touchingColor (Rgb color) const override
 
bool touchingColor (Rgb color, Rgb mask) const override
 
void setGraphicsEffectValue (IGraphicsEffect *effect, double value) override
 
void clearGraphicsEffects () override
 
bool isTarget () const override final
 
virtual bool isStage () const
 
const std::string & name () const
 
void setName (const std::string &name)
 
const std::vector< std::shared_ptr< Variable > > & variables () const
 
int addVariable (std::shared_ptr< Variable > variable)
 
std::shared_ptr< VariablevariableAt (int index) const
 
int findVariable (const std::string &variableName) const
 
int findVariableById (const std::string &id) const
 
ValueData ** variableData ()
 
const std::vector< std::shared_ptr< List > > & lists () const
 
int addList (std::shared_ptr< List > list)
 
std::shared_ptr< ListlistAt (int index) const
 
int findList (const std::string &listName) const
 
int findListById (const std::string &id) const
 
List ** listData ()
 
const std::vector< std::shared_ptr< Block > > & blocks () const
 
int addBlock (std::shared_ptr< Block > block)
 
std::shared_ptr< BlockblockAt (int index) const
 
int findBlock (const std::string &id) const
 
std::vector< std::shared_ptr< Block > > greenFlagBlocks () const
 
const std::vector< std::shared_ptr< Comment > > & comments () const
 
int addComment (std::shared_ptr< Comment > comment)
 
std::shared_ptr< CommentcommentAt (int index) const
 
int findComment (const std::string &id) const
 
int costumeIndex () const
 
std::shared_ptr< CostumecurrentCostume () const
 
const std::vector< std::shared_ptr< Costume > > & costumes () const
 
int addCostume (std::shared_ptr< Costume > costume)
 
std::shared_ptr< CostumecostumeAt (int index) const
 
int findCostume (const std::string &costumeName) const
 
const std::vector< std::shared_ptr< Sound > > & sounds () const
 
int addSound (std::shared_ptr< Sound > sound)
 
std::shared_ptr< SoundsoundAt (int index) const
 
int findSound (const std::string &soundName) const
 
double volume () const
 
void setVolume (double newVolume)
 
virtual double soundEffectValue (Sound::Effect effect) const
 
virtual void setSoundEffectValue (Sound::Effect effect, double value)
 
virtual void clearSoundEffects ()
 
bool touchingSprite (Sprite *sprite) const
 
bool touchingEdge () const
 
double graphicsEffectValue (IGraphicsEffect *effect) const
 
TextBubblebubble ()
 
const TextBubblebubble () const
 
void setEngine (IEngine *engine) override final
 
virtual bool isTextBubble () const
 
int layerOrder () const
 
sigslot::signal< int > & layerOrderChanged () const
 
IEngineengine () const
 

Detailed Description

The Sprite class represents a Scratch sprite.

Member Enumeration Documentation

◆ RotationStyle

Enumerator
AllAround 
LeftRight 
DoNotRotate 

Constructor & Destructor Documentation

◆ Sprite() [1/2]

Sprite::Sprite ( )

Constructs Sprite.

◆ Sprite() [2/2]

libscratchcpp::Sprite::Sprite ( const Sprite & )
delete

Member Function Documentation

◆ addBlock()

int Target::addBlock ( std::shared_ptr< Block > block)
inherited

Adds a block and returns its index.

◆ addComment()

int Target::addComment ( std::shared_ptr< Comment > comment)
inherited

Adds a comment and returns its index.

◆ addCostume()

int Target::addCostume ( std::shared_ptr< Costume > costume)
inherited

Adds a costume and returns its index.

◆ addList()

int Target::addList ( std::shared_ptr< List > list)
inherited

Adds a list and returns its index.

◆ addSound()

int Target::addSound ( std::shared_ptr< Sound > sound)
inherited

Adds a sound and returns its index.

◆ addVariable()

int Target::addVariable ( std::shared_ptr< Variable > variable)
inherited

Adds a variable and returns its index.

◆ blockAt()

std::shared_ptr< Block > Target::blockAt ( int index) const
inherited

Returns the block at index.

◆ blocks()

const std::vector< std::shared_ptr< Block > > & Target::blocks ( ) const
inherited

Returns the list of blocks.

◆ boundingRect()

Rect Sprite::boundingRect ( ) const
overridevirtual

Overrides Target::boundingRect().

Reimplemented from libscratchcpp::Target.

◆ bubble() [1/2]

TextBubble * Target::bubble ( )
inherited

Returns the Bubble of this Target.

◆ bubble() [2/2]

const TextBubble * Target::bubble ( ) const
inherited

Returns the Bubble of this Target.

◆ clearGraphicsEffects()

void Sprite::clearGraphicsEffects ( )
overridevirtual

Overrides Target::clearGraphicsEffects().

Reimplemented from libscratchcpp::Target.

◆ clearSoundEffects()

void Target::clearSoundEffects ( )
virtualinherited

Sets the value of all sound effects to 0 (clears them).

◆ clone()

std::shared_ptr< Sprite > Sprite::clone ( )

Creates a clone of the sprite.

◆ clones()

const std::vector< std::shared_ptr< Sprite > > & Sprite::clones ( ) const

Returns list of clones of the sprite.

◆ cloneSprite()

Sprite * Sprite::cloneSprite ( ) const

Returns the sprite this clone was created from, or nullptr if this isn't a clone.

◆ commentAt()

std::shared_ptr< Comment > Target::commentAt ( int index) const
inherited

Returns the comment at index.

◆ comments()

const std::vector< std::shared_ptr< Comment > > & Target::comments ( ) const
inherited

Returns the list of comments in the code area.

◆ costumeAt()

std::shared_ptr< Costume > Target::costumeAt ( int index) const
inherited

Returns the costume at index.

◆ costumeIndex()

int Target::costumeIndex ( ) const
inherited

Returns the index of the current costume.

◆ costumes()

const std::vector< std::shared_ptr< Costume > > & Target::costumes ( ) const
inherited

Returns the list of costumes.

◆ currentCostume()

std::shared_ptr< Costume > Target::currentCostume ( ) const
inherited

Returns the currently set costume.

◆ currentCostumeHeight()

int Sprite::currentCostumeHeight ( ) const
overridevirtual

Overrides Target::currentCostumeHeight().

Reimplemented from libscratchcpp::Target.

◆ currentCostumeWidth()

int Sprite::currentCostumeWidth ( ) const
overridevirtual

Overrides Target::currentCostumeWidth().

Reimplemented from libscratchcpp::Target.

◆ deleteClone()

void Sprite::deleteClone ( )

Deletes this clone (if the sprite is a clone).

◆ direction()

double Sprite::direction ( ) const

Returns the direction.

◆ draggable()

bool Sprite::draggable ( ) const

Returns true if the sprite is draggable.

◆ dragging()

bool Sprite::dragging ( ) const

Returns true if the sprite is being dragged.

◆ dragToPosition()

void Sprite::dragToPosition ( double x,
double y )

Drags the sprite to the given position.

Note
If startDragging() wasn't called before calling this method, dragging will be started automatically.

◆ engine()

IEngine * Drawable::engine ( ) const
inherited

Returns the engine.

◆ fastBoundingRect()

Rect Sprite::fastBoundingRect ( ) const
overridevirtual

Overrides Target::fastBoundingRect().

Reimplemented from libscratchcpp::Target.

◆ findBlock()

int Target::findBlock ( const std::string & id) const
inherited

Returns the index of the block with the given ID.

◆ findComment()

int Target::findComment ( const std::string & id) const
inherited

Returns the index of the comment with the given ID.

◆ findCostume()

int Target::findCostume ( const std::string & costumeName) const
inherited

Returns the index of the given costume.

◆ findList()

int Target::findList ( const std::string & listName) const
inherited

Returns the index of the list with the given name.

◆ findListById()

int Target::findListById ( const std::string & id) const
inherited

Returns the index of the list with the given ID.

◆ findSound()

int Target::findSound ( const std::string & soundName) const
inherited

Returns the index of the sound with the given name.

◆ findVariable()

int Target::findVariable ( const std::string & variableName) const
inherited

Returns the index of the variable with the given name.

◆ findVariableById()

int Target::findVariableById ( const std::string & id) const
inherited

Returns the index of the variable with the given ID.

◆ getInterface()

ISpriteHandler * Sprite::getInterface ( ) const

Returns the sprite interface.

◆ graphicsEffectValue()

double Target::graphicsEffectValue ( IGraphicsEffect * effect) const
inherited

Returns the value of the given graphics effect.

◆ greenFlagBlocks()

std::vector< std::shared_ptr< Block > > Target::greenFlagBlocks ( ) const
inherited

Returns list of all "when green flag clicked" blocks.

◆ isClone()

bool Sprite::isClone ( ) const

Returns true if this is a clone.

◆ isStage()

virtual bool libscratchcpp::Target::isStage ( ) const
inlinevirtualinherited

Returns true if this Target is the stage.

Reimplemented in libscratchcpp::Stage.

◆ isTarget()

bool Target::isTarget ( ) const
finaloverridevirtualinherited

Returns true.

Reimplemented from libscratchcpp::Drawable.

◆ isTextBubble()

virtual bool libscratchcpp::Drawable::isTextBubble ( ) const
inlinevirtualinherited

Returns true if this Drawable is a TextBubble.

Reimplemented in libscratchcpp::TextBubble.

◆ keepInFence()

void Sprite::keepInFence ( double newX,
double newY,
double * fencedX,
double * fencedY ) const

Keeps the desired position within the stage.

Parameters
[in]Newdesired X position.
[in]Newdesired Y position.
[out]FencedX position.
[out]FencedY position.

◆ layerOrder()

int Drawable::layerOrder ( ) const
inherited

Returns the layer number.

◆ layerOrderChanged()

sigslot::signal< int > & Drawable::layerOrderChanged ( ) const
inherited

Emits when the layer number changes.

◆ listAt()

std::shared_ptr< List > Target::listAt ( int index) const
inherited

Returns the list at index.

◆ listData()

List ** Target::listData ( )
inherited

Returns an array of list pointers (for optimized list access).

◆ lists()

const std::vector< std::shared_ptr< List > > & Target::lists ( ) const
inherited

Returns the list of Scratch lists.

◆ name()

const std::string & Target::name ( ) const
inherited

Returns the name of the target.

◆ rotationStyle()

Sprite::RotationStyle Sprite::rotationStyle ( ) const

Returns the rotation style.

◆ rotationStyleStr()

std::string Sprite::rotationStyleStr ( ) const

Returns the rotation style as a string.

◆ setCostumeIndex()

void Sprite::setCostumeIndex ( int newCostumeIndex)
overridevirtual

Overrides Target::setCostumeIndex().

Reimplemented from libscratchcpp::Target.

◆ setDirection()

void Sprite::setDirection ( double newDirection)

Sets the direction.

◆ setDraggable()

void Sprite::setDraggable ( bool newDraggable)

Toggles whether the sprite is draggable.

◆ setEngine()

void Target::setEngine ( IEngine * engine)
finaloverridevirtualinherited

Overrides Drawable::setEngine().

Reimplemented from libscratchcpp::Drawable.

◆ setGraphicsEffectValue()

void Sprite::setGraphicsEffectValue ( IGraphicsEffect * effect,
double value )
overridevirtual

◆ setInterface()

void Sprite::setInterface ( ISpriteHandler * newInterface)

Sets the sprite interface.

◆ setLayerOrder()

void Sprite::setLayerOrder ( int newLayerOrder)
overridevirtual

Overrides Target::setLayerOrder().

Reimplemented from libscratchcpp::Drawable.

◆ setName()

void Target::setName ( const std::string & name)
inherited

Sets the name of the target.

Note
Setting the name to one of the reserved names (mouse, stage, edge, myself, random) won't do anything.

◆ setPosition()

void Sprite::setPosition ( double x,
double y )

◆ setRotationStyle() [1/3]

void Sprite::setRotationStyle ( const char * newRotationStyle)

Sets the rotation style.

◆ setRotationStyle() [2/3]

void Sprite::setRotationStyle ( const std::string & newRotationStyle)

Sets the rotation style.

◆ setRotationStyle() [3/3]

void Sprite::setRotationStyle ( RotationStyle newRotationStyle)

Sets the rotation style.

◆ setSize()

void Sprite::setSize ( double newSize)

Sets the size.

◆ setSoundEffectValue()

void Target::setSoundEffectValue ( Sound::Effect effect,
double value )
virtualinherited

Sets the value of the given sound effect.

◆ setVisible()

void Sprite::setVisible ( bool newVisible)

Sets the visibility of the sprite.

◆ setVolume()

void Target::setVolume ( double newVolume)
inherited

Sets the volume of all sounds of this target.

◆ setX()

void Sprite::setX ( double newX)

Sets the X position of the sprite.

◆ setY()

void Sprite::setY ( double newY)

Sets the Y position of the sprite.

◆ size()

double Sprite::size ( ) const

Returns the size.

◆ soundAt()

std::shared_ptr< Sound > Target::soundAt ( int index) const
inherited

Returns the sound at index.

◆ soundEffectValue()

double Target::soundEffectValue ( Sound::Effect effect) const
virtualinherited

Returns the value of the given sound effect.

◆ sounds()

const std::vector< std::shared_ptr< Sound > > & Target::sounds ( ) const
inherited

Returns the list of sounds.

◆ startDragging()

void Sprite::startDragging ( )

Starts dragging. Calls to setX(), setY() and setPosition() will be ignored until stopDragging() is called.

◆ stopDragging()

void Sprite::stopDragging ( )

Stops dragging.

◆ touchingColor() [1/2]

bool Sprite::touchingColor ( Rgb color) const
overridevirtual

Overrides Target::touchingColor().

Reimplemented from libscratchcpp::Target.

◆ touchingColor() [2/2]

bool Sprite::touchingColor ( Rgb color,
Rgb mask ) const
overridevirtual

Overrides Target::touchingColor().

Reimplemented from libscratchcpp::Target.

◆ touchingEdge()

bool Target::touchingEdge ( ) const
inherited

Returns true if the target is touching the edge.

◆ touchingPoint()

bool Sprite::touchingPoint ( double x,
double y ) const
overridevirtual

Overrides Target::touchingPoint().

Reimplemented from libscratchcpp::Target.

◆ touchingSprite()

bool Target::touchingSprite ( Sprite * sprite) const
inherited

Returns true if the Target is touching the given Sprite (or its clones).

◆ variableAt()

std::shared_ptr< Variable > Target::variableAt ( int index) const
inherited

Returns the variable at index.

◆ variableData()

ValueData ** Target::variableData ( )
inherited

Returns an array of raw variable data pointers (for optimized variable access).

◆ variables()

const std::vector< std::shared_ptr< Variable > > & Target::variables ( ) const
inherited

Returns the list of variables.

◆ visible()

bool Sprite::visible ( ) const

Returns true if the sprite is visible.

◆ volume()

double Target::volume ( ) const
inherited

Returns the volume.

◆ x()

double Sprite::x ( ) const

Returns the X position of the sprite.

◆ y()

double Sprite::y ( ) const

Returns the Y position of the sprite.


The documentation for this class was generated from the following files: