class documentation

Undocumented

Method __init__ Like Scratch, x,y is in the center of the sprite. Where that is may change based on the costume.
Async Method ask_and_wait @return answer as a string
Method broadcast Undocumented
Method change_size_by Undocumented
Method change_x_by Undocumented
Method change_y_by Undocumented
Method clone Make a shallow clone of this sprite. Important: The cloned sprite is not automatically on the same stage as the original; specify the 'stage' parameter to add the sprite to the stage. Costumes are not reloaded but can be manipulated independently...
Method destroy Undocumented
Method direction_to Bonus: gives the direction in degrees from this Sprite to the given thing. @param what Can be any of * Sprite another sprite - distance center to center * An (x,y) position tuple @return a direction in the range [-180,180), where 0 means the other object is directly above this one.
Method distance_to @param what Can be any of * Sprite another sprite - distance center to center * An (x,y) position tuple
Method forever Undocumented
Method glide_to Glide to the given x, y in the background without waiting. @return The task object which can be waited on for completion.
Async Method glide_to_and_wait Undocumented
Method glide_to_position Similar to glide_to but with single position argument
Async Method glide_to_position_and_wait Similar to glide_to_and_wait but with single position argument
Method go_backward_layers Move this sprite backward the number of layers you specify.
Method go_forward_layers Move this sprite forward the number of layers you specify.
Method go_rect Go to a position determined by the keywords accepted by pygame.Rect.
Method go_to Undocumented
Method go_to_back_layer Move this sprite behind of all other sprites.
Method go_to_front_layer Move this sprite on top of all other sprites.
Method go_to_position Go to the (x,y) postion, given as a tuple. @see scratchypy.random_position() @see scratchypy.mouse_pointer()
Method hide Undocumented
Method if_on_edge_bounce TODO: add padding
Method if_on_edge_snap Undocumented
Method message Sends a message to this sprite. (Bonus extension of Scratch). If there is no message event handler (registered with when_i_receive()), for the given messageName, then the message is ignored. @param messageName The message name, as a string @param argDictionary Optional extra parameters to give as part of the message FIXME: this should post to a queue, not run handler directly?...
Method move Move steps (pixel lengths) in the direction of the current rotation. @param steps Distance to travel. May be a fraction. FIXME for left-right mode
Method next_costume Undocumented
Method point_in_direction Set the *direction* to the given degrees. The sprite will point that direction regardless of its current direction.
Method point_towards Undocumented
Method run Run the async function in the background until completion or until this sprite is destroyed.
Method say Will stay indefinitely or until another say/think. Say None or blank to clear bubble.
Async Method say_and_wait Undocumented
Method set_debug Undocumented
Method set_draggable Undocumented
Method set_rotation_style Use one of the enumerated values.
Method set_size_to Undocumented
Method set_x_to Undocumented
Method set_y_to Undocumented
Method show Undocumented
Method switch_costume_to TODO: support switch by name (file name?) @param number The index (number) of the costume to select. Remember, in Python, counting starts at 0, 1, 2, ...
Method think Will stay indefinitely or until another say/think. Say None or blank to clear bubble.
Async Method think_and_wait Undocumented
Method touching @param what Can be any of * Sprite another sprite - will compare against masks * pygame.sprite.Group [ADVANCED] * An (x,y) position tuple * A pygame.color.Color (but can't be an RGB tuple) * Sprite...
Method touching_color Undocumented
Method touching_edge Undocumented
Method turn Change the direction by the amouny of degrees given in degrees. A positive number is clockwise 🔃. A negative number is counter-clockwise 🔄.
Method update Called once per frame to do updates.
Method when_clicked When this sprite is clicked, call the given handler. The handler is of the form: ``` def myClickHandler(sprite, clickPosition): pass ``` Where 'sprite' is this sprite object where the click was delivered, and clickPosition is the tuple (x,y) position of the click relative to the sprite.
Method when_i_receive Register a callback to call when this sprite receives a message with the given messageName. The handler is of the form: ``` def myMessageHandler(sprite, argDictionary): pass ``` Where 'sprite' is this sprite object where the click was delivered, and the argDictionary is whatever kind of extra information goes with the message, as a dictionary of key, value pairs.
Method when_key_pressed Undocumented
Constant EDGE Undocumented
Property costume_name Undocumented
Property costume_number Undocumented
Property direction The "direction" in Scratch is the angle the character is facing. By default, the cat faces right, 90 degrees - that is equivalent to not being rotated (0 degrees). Direction is in the range -179.99.. to +180 inclusive.
Property name @return the name of the sprite set in the constructor
Property position Undocumented
Property rect Undocumented
Property size @return the size (scaling percent) as a number, where 100% is full size.
Property visible @return True if visible, or False if hide() has been called.
Property x_position sprite.x is an alias for this. @return the x coordinate of the center of this sprite.
Property y_position sprite.y is an alias for this. @return the y coordinate of the center of this sprite.
Method _applyImage Apply scales and transforms to original image, then set sprite vars
Method _loadCostumes Undocumented
Method _make_bubble Undocumented
Method _on_key_down Undocumented
Method _on_mouse_motion Undocumented
Method _render Undocumented
Instance Variable _backgroundTasks Undocumented
Instance Variable _costumeIndex Undocumented
Instance Variable _costumes Undocumented
Instance Variable _debug Undocumented
Instance Variable _draggable Undocumented
Instance Variable _image Undocumented
Instance Variable _keyHandlers Undocumented
Instance Variable _mask Undocumented
Instance Variable _messageHandlers Undocumented
Instance Variable _name Undocumented
Instance Variable _on_click Undocumented
Instance Variable _on_tick Undocumented
Instance Variable _rect Undocumented
Instance Variable _rotation Undocumented
Instance Variable _rotationStyle Undocumented
Instance Variable _sayThinkImages Undocumented
Instance Variable _scale Undocumented
Instance Variable _stage Undocumented
Instance Variable _visible Undocumented
Instance Variable _x Undocumented
Instance Variable _y Undocumented
def __init__(self, costumes, x=None, y=None, topleft=None, topright=None, name=None, size=None, stage=None):

Like Scratch, x,y is in the center of the sprite. Where that is may change based on the costume.

async def ask_and_wait(self, whatisyourname):

@return answer as a string

def broadcast(self, messageName, **kwargs):

Undocumented

def change_size_by(self, percentChange: float):

Undocumented

def change_x_by(self, steps):

Undocumented

def change_y_by(self, steps):

Undocumented

def clone(self, name=None, stage=None):

Make a shallow clone of this sprite. Important: The cloned sprite is not automatically on the same stage as the original; specify the 'stage' parameter to add the sprite to the stage. Costumes are not reloaded but can be manipulated independently. The new sprite is at the same location and with the all the same properties as this sprite. You can change properties or call functions on the new returned object. @param name A unique name for the new sprite, or one will be automatically assigned. @param stage If not None, will be automatically added to the stage.

def destroy(self):

Undocumented

def direction_to(self, what):

Bonus: gives the direction in degrees from this Sprite to the given thing. @param what Can be any of * Sprite another sprite - distance center to center * An (x,y) position tuple @return a direction in the range [-180,180), where 0 means the other object is directly above this one.

def distance_to(self, what):

@param what Can be any of * Sprite another sprite - distance center to center * An (x,y) position tuple

def forever(self, functionToCall):

Undocumented

def glide_to(self, x: float, y: float, seconds: float):

Glide to the given x, y in the background without waiting. @return The task object which can be waited on for completion.

async def glide_to_and_wait(self, x: float, y: float, seconds: float):

Undocumented

def glide_to_position(self, position: Tuple[float, float], seconds: float):

Similar to glide_to but with single position argument

async def glide_to_position_and_wait(self, position: Tuple[float, float], seconds: float):

Similar to glide_to_and_wait but with single position argument

def go_backward_layers(self, howmany: int):

Move this sprite backward the number of layers you specify.

def go_forward_layers(self, howmany: int):

Move this sprite forward the number of layers you specify.

def go_rect(self, **kwargs):

Go to a position determined by the keywords accepted by pygame.Rect.

def go_to(self, x: float, y: float):

Undocumented

def go_to_back_layer(self):

Move this sprite behind of all other sprites.

def go_to_front_layer(self):

Move this sprite on top of all other sprites.

def go_to_position(self, position: Tuple[float, float]):

Go to the (x,y) postion, given as a tuple. @see scratchypy.random_position() @see scratchypy.mouse_pointer()

def hide(self):

Undocumented

def if_on_edge_bounce(self):

TODO: add padding

def if_on_edge_snap(self, padding=0):

Undocumented

def message(self, messageName: str, argDictionary={}):

Sends a message to this sprite. (Bonus extension of Scratch). If there is no message event handler (registered with when_i_receive()), for the given messageName, then the message is ignored. @param messageName The message name, as a string @param argDictionary Optional extra parameters to give as part of the message FIXME: this should post to a queue, not run handler directly?

def move(self, steps: float):

Move steps (pixel lengths) in the direction of the current rotation. @param steps Distance to travel. May be a fraction. FIXME for left-right mode

def next_costume(self):

Undocumented

def point_in_direction(self, degrees: float):

Set the *direction* to the given degrees. The sprite will point that direction regardless of its current direction.

def point_towards(self, positionXY):

Undocumented

def run(self, coroutine):

Run the async function in the background until completion or until this sprite is destroyed.

def say(self, speechText: str = None):

Will stay indefinitely or until another say/think. Say None or blank to clear bubble.

async def say_and_wait(self, speechText: str, howManySeconds: float):

Undocumented

def set_debug(self, onoff=True):

Undocumented

def set_draggable(self, canDrag):

Undocumented

def set_rotation_style(self, style: Literal[DONT_ROTATE, LEFT_RIGHT, ALL_AROUND]):

Use one of the enumerated values.

def set_size_to(self, percent: float):

Undocumented

def set_x_to(self, x):

Undocumented

def set_y_to(self, y):

Undocumented

def show(self):

Undocumented

def switch_costume_to(self, index: int):

TODO: support switch by name (file name?) @param number The index (number) of the costume to select. Remember, in Python, counting starts at 0, 1, 2, ...

def think(self, thoughtText: str):

Will stay indefinitely or until another say/think. Say None or blank to clear bubble.

async def think_and_wait(self, thoughtText: str, howManySeconds: float):

Undocumented

def touching(self, what):

@param what Can be any of * Sprite another sprite - will compare against masks * pygame.sprite.Group [ADVANCED] * An (x,y) position tuple * A pygame.color.Color (but can't be an RGB tuple) * Sprite.EDGE to mean the screen edge.

def touching_color(self, color):

Undocumented

def touching_edge(self):

Undocumented

def turn(self, degrees: float):

Change the direction by the amouny of degrees given in degrees. A positive number is clockwise 🔃. A negative number is counter-clockwise 🔄.

def update(self):

Called once per frame to do updates.

def when_clicked(self, handler):

When this sprite is clicked, call the given handler. The handler is of the form: ``` def myClickHandler(sprite, clickPosition): pass ``` Where 'sprite' is this sprite object where the click was delivered, and clickPosition is the tuple (x,y) position of the click relative to the sprite.

def when_i_receive(self, messageName: str, handlerFunction):

Register a callback to call when this sprite receives a message with the given messageName. The handler is of the form: ``` def myMessageHandler(sprite, argDictionary): pass ``` Where 'sprite' is this sprite object where the click was delivered, and the argDictionary is whatever kind of extra information goes with the message, as a dictionary of key, value pairs.

def when_key_pressed(self, key, functionToCall):

Undocumented

EDGE: int =

Undocumented

Value
99
@property
costume_name: str =

Undocumented

@property
costume_number: int =

Undocumented

@property
direction: float =

The "direction" in Scratch is the angle the character is facing. By default, the cat faces right, 90 degrees - that is equivalent to not being rotated (0 degrees). Direction is in the range -179.99.. to +180 inclusive.

@property
name =

@return the name of the sprite set in the constructor

@property
position: Tuple[float, float] =

Undocumented

@property
rect =

Undocumented

@property
size: float =

@return the size (scaling percent) as a number, where 100% is full size.

@property
visible =

@return True if visible, or False if hide() has been called.

@property
x_position: float =

sprite.x is an alias for this. @return the x coordinate of the center of this sprite.

@property
y_position: float =

sprite.y is an alias for this. @return the y coordinate of the center of this sprite.

def _applyImage(self):

Apply scales and transforms to original image, then set sprite vars

def _loadCostumes(self, listOfImages):

Undocumented

def _make_bubble(self, speechText: str):

Undocumented

def _on_key_down(self, event):

Undocumented

def _on_mouse_motion(self, event):

Undocumented

def _render(self, screen):

Undocumented

_backgroundTasks =

Undocumented

_costumeIndex =

Undocumented

_costumes: list =

Undocumented

_debug =

Undocumented

_draggable =

Undocumented

_image =

Undocumented

_keyHandlers: dict =

Undocumented

_mask =

Undocumented

_messageHandlers: dict =

Undocumented

_name =

Undocumented

_on_click =

Undocumented

_on_tick =

Undocumented

_rect =

Undocumented

_rotation: int =

Undocumented

_rotationStyle =

Undocumented

_sayThinkImages =

Undocumented

_scale =

Undocumented

_stage =

Undocumented

_visible: bool =

Undocumented

_x =

Undocumented

_y =

Undocumented