class Sprite(pygame.sprite.Sprite):
Known subclasses: scratchypy.sprite.AnimatedSprite, scratchypy.sprite.TextSprite
Constructor: Sprite(costumes, x, y, topleft, ...)
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 |
@return answer as a string |
| Method | broadcast |
Undocumented |
| Method | change |
Undocumented |
| Method | change |
Undocumented |
| Method | change |
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 |
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 |
@param what Can be any of * Sprite another sprite - distance center to center * An (x,y) position tuple |
| Method | forever |
Undocumented |
| Method | glide |
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 |
Undocumented |
| Method | glide |
Similar to glide_to but with single position argument |
| Async Method | glide |
Similar to glide_to_and_wait but with single position argument |
| Method | go |
Move this sprite backward the number of layers you specify. |
| Method | go |
Move this sprite forward the number of layers you specify. |
| Method | go |
Go to a position determined by the keywords accepted by pygame.Rect. |
| Method | go |
Undocumented |
| Method | go |
Move this sprite behind of all other sprites. |
| Method | go |
Move this sprite on top of all other sprites. |
| Method | go |
Go to the (x,y) postion, given as a tuple. @see scratchypy.random_position() @see scratchypy.mouse_pointer() |
| Method | hide |
Undocumented |
| Method | if |
TODO: add padding |
| Method | if |
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 |
Undocumented |
| Method | point |
Set the *direction* to the given degrees. The sprite will point that direction regardless of its current direction. |
| Method | point |
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 |
Undocumented |
| Method | set |
Undocumented |
| Method | set |
Undocumented |
| Method | set |
Use one of the enumerated values. |
| Method | set |
Undocumented |
| Method | set |
Undocumented |
| Method | set |
Undocumented |
| Method | show |
Undocumented |
| Method | switch |
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 |
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 |
Undocumented |
| Method | touching |
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 |
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 |
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 |
Undocumented |
| Constant | EDGE |
Undocumented |
| Property | costume |
Undocumented |
| Property | costume |
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 |
sprite.x is an alias for this. @return the x coordinate of the center of this sprite. |
| Property | y |
sprite.y is an alias for this. @return the y coordinate of the center of this sprite. |
| Method | _apply |
Apply scales and transforms to original image, then set sprite vars |
| Method | _load |
Undocumented |
| Method | _make |
Undocumented |
| Method | _on |
Undocumented |
| Method | _on |
Undocumented |
| Method | _render |
Undocumented |
| Instance Variable | _background |
Undocumented |
| Instance Variable | _costume |
Undocumented |
| Instance Variable | _costumes |
Undocumented |
| Instance Variable | _debug |
Undocumented |
| Instance Variable | _draggable |
Undocumented |
| Instance Variable | _image |
Undocumented |
| Instance Variable | _key |
Undocumented |
| Instance Variable | _mask |
Undocumented |
| Instance Variable | _message |
Undocumented |
| Instance Variable | _name |
Undocumented |
| Instance Variable | _on |
Undocumented |
| Instance Variable | _on |
Undocumented |
| Instance Variable | _rect |
Undocumented |
| Instance Variable | _rotation |
Undocumented |
| Instance Variable | _rotation |
Undocumented |
| Instance Variable | _say |
Undocumented |
| Instance Variable | _scale |
Undocumented |
| Instance Variable | _stage |
Undocumented |
| Instance Variable | _visible |
Undocumented |
| Instance Variable | _x |
Undocumented |
| Instance Variable | _y |
Undocumented |
scratchypy.sprite.AnimatedSprite, scratchypy.sprite.TextSpriteLike Scratch, x,y is in the center of the sprite. Where that is may change based on the costume.
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.
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.
@param what Can be any of * Sprite another sprite - distance center to center * An (x,y) position tuple
Glide to the given x, y in the background without waiting. @return The task object which can be waited on for completion.
Go to the (x,y) postion, given as a tuple. @see scratchypy.random_position() @see scratchypy.mouse_pointer()
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?
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
Set the *direction* to the given degrees. The sprite will point that direction regardless of its current direction.
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, ...
@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.
Change the direction by the amouny of degrees given in degrees. A positive number is clockwise 🔃. A negative number is counter-clockwise 🔄.
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.
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.
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.