new Sprite()
Base class for all sprites and shapes
Example
sprite = codesters.Sprite('fox')
Methods
(static) ask(question) → {string}
ask() prompts the user for input which is returned as a string
Parameters:
Name | Type | Description |
---|---|---|
question |
string | This is the question the user will be answering |
Returns:
user input
- Type
- string
Example
sprite.ask("What is your favorite color?")
(static) back(distance)
back() animates a sprite in the opposite direction of its current rotation.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.back(150)
(static) backward(distance)
backward() animates a sprite in the opposite direction of its current rotation.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.backward(150)
(static) cannot_collide()
cannot_collide() prevents this sprite from triggering collision events for itself or with other sprites.
Example
sprite.cannot_collide()
(static) click_x()
click_x() returns the stage x coordinate where the user previously clicked after a click event occurred for this sprite.
Example
def event(){
x = sprite.click_x() # x coordinate on the stage the click happened
y = sprite.click_y() # y coordinate on the stage the click happened
}
sprite.event_click(event)
(static) click_y()
click_y() returns the stage y coordinate where the user previously clicked after a click event occurred for this sprite.
Example
def event(){
x = sprite.click_x() # x coordinate on the stage the click happened
y = sprite.click_y() # y coordinate on the stage the click happened
}
sprite.event_click(event)
(static) collision_goal_off()
collision_goal_off() removes the goal status of a sprite that is a goal.
Example
sprite.collision_goal_off()
(static) collision_goal_on()
collision_goal_on() makes it so that this sprite triggers a collision_goal event if another sprite collides with it.
Example
sprite.collision_goal_on()
(static) collision_hazard_off()
collision_hazard_off() prevents the sprite from triggering a collision_hazard event if another sprite collides with it.
Example
sprite.collision_hazard_off()
(static) collision_hazard_on()
collision_hazard_on() allows the sprite to trigger a collision_hazard event if another sprite collides with it.
Example
sprite.collision_hazard_on()
(static) collision_off()
collision_off() prevents this sprite from triggering collision events for itself or with other sprites.
Example
sprite = codesters.Sprite('fox')
def collide(sprite, hit_sprite):
# this runs when the sprite collides with another sprite
sprite.collision_off() # this sprite will no longer cause collision events after this first collision
sprite.collision_on() # now collisions events are turned back on for this sprite
sprite.event_collision(collide)
(static) collision_on()
collision_on() allows this sprite to trigger collision events for itself or for other sprites
Example
sprite = codesters.Sprite('fox')
def collide(sprite, hit_sprite):
# this runs when the sprite collides with another sprite
sprite.collision_off() # this sprite will no longer cause collision events after this first collision
sprite.collision_on() # now collisions events are turned back on for this sprite
sprite.event_collision(collide)
(static) debug()
debug() logs the sprite to the JavaScript console
Example
sprite.debug()
(static) dilate(amount)
dilate() dilates the sprite around the origin
Parameters:
Name | Type | Description |
---|---|---|
amount |
number | the amount to dilate |
Example
sprite.dilate(2)
(static) direction() → {number}
direction() returns the heading of the sprite
Returns:
heading of the sprite
- Type
- number
Example
sprite.direction()
(static) draw_hitbox()
draw_hitbox() the sprite draws its hitbox
Example
sprite.draw_hitbox()
(static) event_click(functionName)
event_click() sets an function to run when this sprite is clicked.
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the mouse is clicked. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_click(event)
(static) event_collision(functionName)
event_collision() sets an function to run when the sprite collides with another sprite. Any sprite can be set with .cannot_collide() to prevent it from triggering collision events.
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the sprite collides with something. Also accepts None to disable this event. |
Example
s1 = codesters.Sprite('fox')
s2 = codesters.Sprite('cat')
def event(sprite, hit_sprite){
# this will run if 's1' collides with 's2'
# in the scope of this function, the argument 'sprite' refers to 's1' and 'hit_sprite' refers to 's2'
}
s1.event_collision(event)
(static) event_collision_goal(functionName)
event_collision_goal() sets an function to run when the sprite collides with a sprite that is set as is_goal()
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the sprite collides with a goal. Also accepts None to disable this event. |
Example
sprite = codesters.Sprite('fox')
goal = codesters.Square()
goal.is_goal()
def event(sprite, hit_sprite){
# this will run when 'sprite' collides with 'goal'
}
sprite.event_collision_goal(event)
(static) event_collision_hazard(functionName)
event_collision_goal() sets an function to run when the sprite collides with a sprite that is set as is_hazard()
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the sprite collides with a hazard. Also accepts None to disable this event. |
Example
sprite = codesters.Sprite('fox')
hazard = codesters.Square()
hazard.is_hazard()
def event(sprite, hit_sprite){
# this will run when 'sprite' collides with 'hazard'
}
sprite.event_collision_hazard(event)
(static) event_delay(functionName, seconds)
event_delay() sets an function to run once after a specified number of seconds.
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when after the specified number of seconds |
seconds |
number | number of seconds before calling the function. Accepts decimals also. |
Example
def run_once(){
# this will run once after 2 seconds
}
sprite.event_delay(run_once, 2)
* def keep_running(){
# this will keep running every 2 seconds
# because it sets a new event delay in the event itself.
sprite.event_delay(keep_running, 2)
}
sprite.event_delay(keep_running, 2)
(static) event_down_key(functionName)
event_down_key() sets an function to run when the down key is pressed
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the down key is pressed. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_down_key(event)
(static) event_enter_key(functionName)
event_enter_key() sets an function to run when the enter key is pressed
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the enter key is pressed. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_enter_key(event)
(static) event_forever(functionName)
event_forever() sets an function to run forever. This function will run every frame. Using animations in a forever event may cause unexpected behavior.
You may want to try event_delay() instead to have more control over how often the function will run.
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run forever. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_forever(event)
(static) event_key(keyString, functionName)
event_key() sets an function to run when a given key is pressed
Parameters:
Name | Type | Description |
---|---|---|
keyString |
string | the key to call the function |
functionName |
function | function to run when the given key is pressed. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_key('a', event)
(static) event_left_key(functionName)
event_left_key() sets a function to run when the left key is pressed. Event can be cleared by passing None as an argument.
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to happen when the left key is pressed. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_left_key(event)
(static) event_right_key(functionName)
event_right_key() sets an function to run when the right key is pressed
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the right key is pressed. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_right_key(event)
(static) event_space_key(functionName)
event_space_key() sets an function to run when the space key is pressed
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the space key is pressed. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_space_key(event)
(static) event_up_key(functionName)
event_up_key() sets an function to run when the up key is pressed
Parameters:
Name | Type | Description |
---|---|---|
functionName |
function | function to run when the up key is pressed. Also accepts None to disable this event. |
Example
def event(sprite){
#actions
}
sprite.event_up_key(event)
(static) face_backward()
face_backward() makes the sprite face backward
Example
sprite.face_backwark()
(static) face_forward()
face_forward() makes the sprite face forward
Example
sprite.face_forward()
(static) face_rightside_up()
face_rightside_up() makes the sprite face rightside-up
Example
sprite.face_rightside_up()
(static) face_upside_down()
face_upside_down() makes the sprite face upside-down
Example
sprite.face_upside_down()
(static) fill()
fill() If a shape was created without a fill color, this method fills the shape color
Example
shape.fill()
(static) fill_off()
fill_off() stops filling the shape the sprite draws to the stage.
Example
sprite.fill_off()
(static) fill_on()
fill_on() when pen_down() is enabled the sprite will fill in the shape it draws to the stage.
Example
sprite.fill_on()
(static) fill_toggle()
fill_toggle() toggles the sprite filling filling the shape it draws to the stage.
Example
sprite.fill_toggle()
(static) flip_down_up()
flip_down_up() flips the sprite vertically
Example
sprite.flip_down_up()
(static) flip_horizontal()
flip_horizontal() flips the sprite horizontally
Example
sprite.flip_horizontal()
(static) flip_left_right()
flip_left_right() flips the sprite horizontally
Example
sprite.flip_left_right()
(static) flip_right_left()
flip_right_left() flips the sprite horizontally
Example
sprite.flip_right_left()
(static) flip_up_down()
flip_up_down() flips the sprite vertically
Example
sprite.flip_up_down()
(static) flip_vertical()
flip_vertical() flips the sprite vertically
Example
sprite.flip_vertical()
(static) forward(distance)
forward() animates a sprite in the direction of its current rotation.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.forward(150)
(static) get_bottom() → {number}
get_bottom() returns the y-coordinate of the bottom edge of the sprite
Returns:
y-coordinate of the bottom edge of the sprite
- Type
- number
Example
sprite.get_bottom()
(static) get_color() → {color}
get_color() returns the color of the sprite when the sprite is a Shape type sprite (Square, Circle, etc.)
Returns:
color of the sprite
- Type
- color
Example
sprite.get_color()
(static) get_color_hex() → {hex}
get_color_hex() returns the hex code of the color of the sprite when the sprite is a Shape type sprite (Square, Circle, etc.)
Returns:
hex code of the color of the sprite
- Type
- hex
Example
sprite.get_color_hex()
(static) get_composite_speed() → {number}
get_composite_speed() returns the total velocity of the sprite
Returns:
total velocity of the sprite
- Type
- number
Example
sprite.get_composite_speed()
(static) get_direction() → {number}
get_rotation() returns the heading of the sprite
Returns:
heading of the sprite
- Type
- number
Example
sprite.get_direction()
(static) get_fill_color() → {color}
get_fill_color() returns the fill color of the sprite when the sprite is a Shape type sprite (Square, Circle, etc.)
Returns:
fill color of the sprite
- Type
- color
Example
sprite.get_fill_color()
(static) get_fill_off() → {bool}
get_fill_off() returns whether the fill is off
Returns:
whether the fill is off
- Type
- bool
Example
sprite.get_fill_off()
(static) get_fill_on() → {bool}
get_fill_on() returns whether the fill is on
Returns:
whether the fill is on
- Type
- bool
Example
sprite.get_fill_on()
(static) get_flip() → {bool}
get_flip() returns whether the sprite is flipped from its default position
Returns:
whether the sprite is flipped from its default position
- Type
- bool
Example
sprite.get_flip()
(static) get_height() → {number}
get_height() returns the height of the sprite
Returns:
height of the sprite
- Type
- number
Example
sprite.get_height()
(static) get_image_name() → {string}
get_image_name() returns the name of the image of the sprite
Returns:
name of the image of the sprite
- Type
- string
Example
sprite.get_image_name()
(static) get_left() → {number}
get_left() returns the x-coordinate of the left edge of the sprite
Returns:
x-coordinate of the left edge of the sprite
- Type
- number
Example
sprite.get_left()
(static) get_name() → {string}
get_name() returns the name of the sprite
Returns:
name of the sprite
- Type
- string
Example
sprite.get_name()
(static) get_outline_color() → {color}
get_outline_color() returns the outline color of the sprite when the sprite is a Shape type sprite (Square, Circle, etc.)
Returns:
outline color of the sprite
- Type
- color
Example
sprite.get_outline_color()
(static) get_pen_down() → {bool}
get_pen_down() returns whether the pen is down
Returns:
whether the pen is down
- Type
- bool
Example
sprite.get_pen_down()
(static) get_pen_up() → {bool}
get_pen_up() returns whether the pen is up
Returns:
whether the pen is up
- Type
- bool
Example
sprite.get_pen_up()
(static) get_right() → {number}
get_right() returns the x-coordinate of the right edge of the sprite
Returns:
x-coordinate of the right edge of the sprite
- Type
- number
Example
sprite.get_right()
(static) get_rotation() → {number}
get_rotation() returns the angle of the sprite
Returns:
angle of the sprite
- Type
- number
Example
sprite.get_rotation()
(static) get_say_text() → {string}
get_say_text() returns the text the sprite previously said using the .say() command
Returns:
text the sprite says
- Type
- string
Example
sprite.get_say_text()
(static) get_scale() → {number}
get_scale() returns the scale of the sprite
Returns:
scale of the sprite
- Type
- number
Example
sprite.get_scale()
(static) get_sides() → {number}
get_sides() returns the number of sides of the sprite (returns 0 if sprite is not a distinct shape)
Returns:
number of sides of the sprite (0 if sprite is not a distinct shape)
- Type
- number
Example
sprite.get_sides()
(static) get_size() → {number}
get_size() returns the size of the sprite
Returns:
size of the sprite
- Type
- number
Example
sprite.get_size()
(static) get_speed() → {number}
get_speed() gets the speed of non-physics animations
Returns:
speed of sprite
- Type
- number
Example
sprite.get_speed()
(static) get_text() → {string}
get_text() returns the text of the sprite (None if not applicable)
Returns:
text of the sprite (None if not applicable)
- Type
- string
Example
sprite.get_text()
(static) get_top() → {number}
get_top() returns the y-coordinate of the top edge of the sprite
Returns:
y-coordinate of the top edge of the sprite
- Type
- number
Example
sprite.get_top()
(static) get_total_wait_time() → {number}
get_total_wait_time() gets the total amount of seconds a sprite has waited. Zero if no previous wait() calls on the sprite.
Returns:
total wait time
- Type
- number
Example
sprite.wait(3)
sprite.wait(4)
waittime = sprite.get_total_wait_time()
print waittime # prints 7
(static) get_type() → {string}
get_type() returns the type of the sprite
Returns:
type of the sprite
- Type
- string
Example
sprite.get_type()
(static) get_wait_time() → {number}
get_wait_time() gets the amount of seconds waited during the sprite's most recent wait(). Zero if no previous wait() calls on the sprite.
Returns:
most recent wait call time
- Type
- number
Example
sprite.wait(3)
waittime = sprite.get_wait_time()
print waittime # prints 3
(static) get_width() → {number}
get_width() returns the width of the sprite
Returns:
width of the sprite
- Type
- number
Example
sprite.get_width()
(static) get_x() → {number}
get_x() returns the x-coordinate of the sprite
Returns:
x-coordinate of the sprite
- Type
- number
Example
sprite.get_x()
(static) get_x_scale() → {number}
get_x_scale() returns the scale of the sprite on the x axis
Returns:
scale of the sprite on the x axis
- Type
- number
Example
sprite.get_x_scale()
(static) get_x_speed() → {number}
get_x_speed() returns the velocity of the sprite in the x direction
Returns:
velocity of the sprite in the x direction
- Type
- number
Example
sprite.get_x_speed()
(static) get_y() → {number}
get_y() returns the y-coordinate of the sprite
Returns:
y-coordinate of the sprite
- Type
- number
Example
sprite.get_y()
(static) get_y_scale() → {number}
get_y_scale() returns the scale of the sprite on the y axis
Returns:
scale of the sprite on the y axis
- Type
- number
Example
sprite.get_y_scale()
(static) get_y_speed() → {number}
get_y_speed() returns the velocity of the sprite in the y direction
Returns:
velocity of the sprite in the y direction
- Type
- number
Example
sprite.get_y_speed()
(static) glide_to(x, y)
glide_to() animates a sprite moving to the point on the stage corresponding to the x and y parameters passed by the user.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
Example
sprite.glide_to(45,70)
(static) go_to(x, y)
go_to() immediately moves a sprite to the point on the stage corresponding to the x and y parameters passed by the user.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
Example
sprite.go_to(45,70)
(static) goto(x, y)
goto() immediately moves a sprite to the point on the stage corresponding to the x and y parameters passed by the user.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
Example
sprite.goto(45,70)
(static) gravity_off()
gravity_off() causes the given sprite to be unaffected by gravity
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.gravity_off() # sprite stops falling
sprite.gravity_on() # sprite falls again
(static) gravity_on()
gravity_on() allows the given sprite to be affected by gravity
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.gravity_off() # sprite stops falling
sprite.gravity_on() # sprite falls again
(static) hide()
hide() hides a sprite or shape. This will also disable collisions.
Example
sprite = codesters.Sprite('fox') # now you see me
sprite.hide() # now you don't
sprite.show() # now you do again.
(static) is_goal()
is_goal() makes it so that this sprite triggers a collision_goal event if another sprite collides with it.
Example
sprite.is_goal()
(static) is_hazard()
is_hazard() allows the sprite to trigger a collision_hazard event of another sprite.
Example
sprite.is_hazard()
(static) jump(speed) → {string}
jump() sets the vertical speed of the sprite to the passed number
Parameters:
Name | Type | Description |
---|---|---|
speed |
number | The |
Returns:
user input
- Type
- string
Example
sprite.jump(2)
(static) left(degrees)
left() animates a rotation of the sprite x degrees counterclockwise. If x is negative, it animates a rotation of the sprite x degrees clockwise
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number |
Example
sprite.left(45)
(static) move_back(distance)
move_back() animates a sprite in the opposite direction of its current rotation.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_back(150)
(static) move_backward(distance)
move_backward() animates a sprite in the opposite direction of its current rotation.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_backward(150)
(static) move_down(distance)
move_down() animates a sprite or shape downwards.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_down(150)
(static) move_forward(distance)
move_forward() animates a sprite in the direction of its current rotation.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_forward(150)
(static) move_left(distance)
move_left() animates a sprite or shape to the left.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_left(150)
(static) move_right(distance)
move_right() animates a sprite or shape to the right.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_right(150)
(static) move_up(distance)
move_up() animates a sprite or shape upwards.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_up(150)
(static) move_x(distance)
move_x() animates a sprite horizontally. If the number passed to move_x() is positive, the sprite will move right. If the number passed to move_x() is negative, the sprite will move left.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_x(150)
(static) move_y(distance)
move_y() animates a sprite vertically. If the number passed to move_y() is positive, the sprite will move up. If the number passed to move_y() is negative, the sprite will move down.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.move_y(150)
(static) movex(distance)
movex() animates a sprite horizontally. If the number passed to movex() is positive, the sprite will move right. If the number passed to movex() is negative, the sprite will move left.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.movex(150)
(static) movey(distance)
movey() animates a sprite vertically. If the number passed to movey() is positive, the sprite will move up. If the number passed to movey() is negative, the sprite will move down.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.movey(150)
(static) pause()
pause() (In Development) pauses the current animation.
Example
sprite.pause()
(static) pen_clear()
pen_clear() clears all drawings from the sprite
Example
sprite.pen_clear()
(static) pen_down()
pen_down() starts the sprite drawing to the stage
Example
sprite.pen_down()
(static) pen_size(size)
pen_size() sets the size of the sprite's pen
Parameters:
Name | Type | Description |
---|---|---|
size |
number | the size of the pen |
Example
sprite.pen_size(5)
(static) pen_toggle()
pen_toggle() toggles the sprite drawing to the stage
Example
sprite.pen_toggle()
(static) pen_up()
pen_up() stops the sprite drawing to the stage
Example
sprite.pen_up()
(static) pen_width(width)
pen_width() sets the width of the sprite's pen
Parameters:
Name | Type | Description |
---|---|---|
width |
number | the width of the pen |
Example
sprite.pen_width(5)
(static) physics_off()
physics_off() causes the given sprite to be unaffected by physics (gravity, speed and collisions)
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.set_x_speed(3) # sprite starts moving right while falling
sprite.physics_off() # sprite stops moving and falling
sprite.physics_on() # sprite starts falling and moving again
(static) physics_on()
physics_on() allows the given sprite to be affected by physics (gravity, speed, collisions)
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.set_x_speed(3) # sprite starts moving right while falling
sprite.physics_off() # sprite stops moving and falling
sprite.physics_on() # sprite starts falling and moving again
(static) play()
play() (In Development) plays a gif sprite OR plays a paused animation.
Example
sprite.play()
(static) point_towards(x, y)
point_towards() points the sprite toward a coordinate.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
Example
sprite.point_towards(45,70)
(static) reflect_x(x)
reflect_x() reflects the sprite across a given vertical
Parameters:
Name | Type | Description |
---|---|---|
x |
number | the x-coordinate of the vertical across which to reflect |
Example
sprite.reflect_x(0)
(static) reflect_x_axis()
reflect_x_axis() reflects the sprite across the x-axis
Example
sprite.reflect_x_axis()
(static) reflect_y(y)
reflect_y() reflects the sprite across a given horizontal
Parameters:
Name | Type | Description |
---|---|---|
y |
number | the y-coordinate of the horizontal across which to reflect |
Example
sprite.reflect_y(0)
(static) reflect_y_axis()
reflect_y_axis() reflects the sprite across the y-axis
Example
sprite.reflect_y_axis()
(static) reset()
reset() (In Development) stops the sprite's current animations.
Example
sprite.reset()
(static) reset_animation()
reset_animation() stops the sprite's current animation. Has no effect if the sprite is not mid-animation
Example
sprite.reset_animation()
(static) right(degrees)
right() animates a rotation of the sprite x degrees clockwise. If x is negative, it animates a rotation of the sprite x degrees counterclockwise
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number |
Example
sprite.right(45)
(static) rotate_about(degrees, x, y)
rotate_about() rotates the sprite around the given point
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number | the degrees to rotate |
x |
number | the x-coordinate of the point around which to rotate |
y |
number | the y-coordinate of the point around which to rotate |
Example
sprite.dilate(90, 0, 0)
(static) rotate_origin(degrees)
rotate_origin() rotates the sprite around the origin
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number | the degrees to rotate |
Example
sprite.rotate_origin(90)
(static) rotation() → {number}
rotation() returns the angle of the sprite
Returns:
angle of the sprite
- Type
- number
Example
sprite.rotation()
(static) say(text, secondsopt, coloropt, sizeopt, fontopt)
say() displays text directly above the sprite
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
string | ||
seconds |
number |
<optional> |
time text remains on screen |
color |
string |
<optional> |
(HTML color name) |
size |
number |
<optional> |
size of text |
font |
string |
<optional> |
(HTML font name) |
Examples
sprite.say("What's up?")
sprite.say("I am a sprite.", 2, "blue", 72)
(static) set_bottom(y)
set_bottom() moves the bottom edge of the sprite to a given y-coordinate
Parameters:
Name | Type | Description |
---|---|---|
y |
number | y-coordinate |
Example
sprite.set_bottom(100)
(static) set_color(color)
set_color() sets the color of the sprite when the sprite is a Shape type sprite (Square, Circle, etc.)
Parameters:
Name | Type | Description |
---|---|---|
color |
color | the color of the sprite |
Example
sprite.set_color('blue')
(static) set_direction(x, y)
set_direction() points the sprite toward a coordinate.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
Example
sprite.set_direction(45,70)
(static) set_drag_off()
set_drag_off() prevents the sprite from being dragged around the stage with the mouse.
Example
sprite.set_drag_off()
(static) set_drag_on()
set_drag_on() allows the sprite to be dragged around the stage with the mouse.
Example
sprite.set_drag_on()
(static) set_fill_color(color)
set_fill_color() sets the fill color of the sprite when the sprite is a Shape type sprite (Square, Circle, etc.)
Parameters:
Name | Type | Description |
---|---|---|
color |
color | the fill color of the sprite |
Example
sprite.set_fill_color('blue')
(static) set_gravity_off()
set_gravity_off() causes the given sprite to be unaffected by gravity
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.gravity_off() # sprite stops falling
sprite.gravity_on() # sprite falls again
(static) set_gravity_on()
set_gravity_on() allows the given sprite to be affected by gravity
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.gravity_off() # sprite stops falling
sprite.gravity_on() # sprite falls again
(static) set_heading(heading)
set_heading() sets the direction of the sprite
Parameters:
Name | Type | Description |
---|---|---|
heading |
number | heading |
Example
sprite.set_heading(90)
(static) set_height(height)
set_height() sets the height of the sprite
Parameters:
Name | Type | Description |
---|---|---|
height |
number |
Example
sprite.set_height(50)
(static) set_left(x)
set_left() moves the left edge of the sprite to a given x-coordinate
Parameters:
Name | Type | Description |
---|---|---|
x |
number | x-coordinate |
Example
sprite.set_left(100)
(static) set_opacity(opacity)
set_opacity() sets the opacity of the sprite
Parameters:
Name | Type | Description |
---|---|---|
opacity |
number | obacity |
Example
sprite.set_opacity(0)
(static) set_outline_color(color)
set_outline_color() sets the outline color of the sprite when the sprite is a Shape type sprite (Square, Circle, etc.)
Parameters:
Name | Type | Description |
---|---|---|
color |
color | the outline color of the sprite |
Example
sprite.set_outline_color('blue')
(static) set_physics_off()
set_physics_off() causes the given sprite to be unaffected by physics (gravity, speed and collisions)
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.set_x_speed(3) # sprite starts moving right while falling
sprite.physics_off() # sprite stops moving and falling
sprite.physics_on() # sprite starts falling and moving again
(static) set_physics_on()
set_physics_on() allows the given sprite to be affected by physics (gravity, speed, collisions)
Example
sprite = codesters.Sprite('fox')
stage.set_gravity(10) # sprite starts falling
sprite.set_x_speed(3) # sprite starts moving right while falling
sprite.physics_off() # sprite stops moving and falling
sprite.physics_on() # sprite starts falling and moving again
(static) set_position(x, y)
set_position() sets the position of the sprite
Parameters:
Name | Type | Description |
---|---|---|
x |
number | x-coordinate |
y |
number | y-coordinate |
Example
sprite.set_position(50,50)
(static) set_right(x)
set_right() moves the right edge of the sprite to a given x-coordinate
Parameters:
Name | Type | Description |
---|---|---|
x |
number | x-coordinate |
Example
sprite.set_right(100)
(static) set_rotation(angle)
set_rotation() sets the angle of the sprite
Parameters:
Name | Type | Description |
---|---|---|
angle |
number | angle |
Example
sprite.set_rotation(90)
(static) set_say_color(color)
set_say_color() sets the color of the "say" text that is drawn after calling .say() on this sprite
Parameters:
Name | Type | Description |
---|---|---|
color |
color | the outline color of the sprite |
Example
sprite.set_say_color('blue')
sprite.say('Hello!')
(static) set_size(size)
set_size() sets the size of the sprite
Parameters:
Name | Type | Description |
---|---|---|
size |
number |
Example
sprite.set_size(1)
(static) set_speed(speed)
set_speed() sets the speed of non-physics animations such as go_to and move_right
Parameters:
Name | Type | Description |
---|---|---|
speed |
number |
Example
sprite.set_speed(1)
(static) set_top(y)
set_top() moves the top edge of the sprite to a given y-coordinate
Parameters:
Name | Type | Description |
---|---|---|
y |
number | y-coordinate |
Example
sprite.set_top(100)
(static) set_velx(x)
set_velx() sets the horizontal velocity of the sprite
Parameters:
Name | Type | Description |
---|---|---|
x |
number | velocity |
Example
sprite.set_velx(50)
(static) set_vely(y)
set_vely() sets the vertical velocity of the sprite
Parameters:
Name | Type | Description |
---|---|---|
y |
number | velocity |
Example
sprite.set_vely(50)
(static) set_width(width)
set_width() sets the width of the sprite
Parameters:
Name | Type | Description |
---|---|---|
width |
number |
Example
sprite.set_width(50)
(static) set_x(y)
set_x() sets the x coordinate of the sprite
Parameters:
Name | Type | Description |
---|---|---|
y |
number | coordinate |
Example
sprite.set_x(50)
(static) set_x_speed(x)
set_x_speed() sets the horizontal velocity of the sprite
Parameters:
Name | Type | Description |
---|---|---|
x |
number | velocity |
Example
sprite.set_x_speed(50)
(static) set_y(y)
set_y() sets the y coordinate of the sprite
Parameters:
Name | Type | Description |
---|---|---|
y |
number | coordinate |
Example
sprite.set_y(50)
(static) set_y_speed(y)
set_y_speed() sets the vertical velocity of the sprite
Parameters:
Name | Type | Description |
---|---|---|
y |
number | velocity |
Example
sprite.set_y_speed(50)
(static) show()
show() will cause a sprite or shape to become visible if it is currently hidden with hide().
Example
sprite = codesters.Sprite('fox') # now you see me
sprite.hide() # now you don't
sprite.show() # now you do again.
(static) speed(speed)
speed() sets the speed of non-physics animations such as go_to and move_right
Parameters:
Name | Type | Description |
---|---|---|
speed |
number |
Example
sprite.speed(1)
(static) stop()
stop() stops the sprite's current animation
Example
sprite.stop()
(static) translate_x(distance)
translate_x() animates a sprite horizontally. If the number passed to translate_x() is positive, the sprite will move right. If the number passed to translate_x() is negative, the sprite will move left.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.translate_x(150)
(static) translate_y(distance)
translate_y() animates a sprite vertically. If the number passed to translate_y() is positive, the sprite will move up. If the number passed to translate_y() is negative, the sprite will move down.
Parameters:
Name | Type | Description |
---|---|---|
distance |
number |
Example
sprite.translate_y(150)
(static) turn_clockwise(degrees)
turn_clockwise() animates a rotation of the sprite x degrees clockwise. If x is negative, it animates a rotation of the sprite x degrees counterclockwise
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number |
Example
sprite.turn_clockwise(45)
(static) turn_counterclockwise(degrees)
turn_counterclockwise() animates a rotation of the sprite x degrees counterclockwise. If x is negative, it animates a rotation of the sprite x degrees clockwise
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number |
Example
sprite.turn_counterclockwise(45)
(static) turn_left(degrees)
turn_left() animates a rotation of the sprite x degrees counterclockwise. If x is negative, it animates a rotation of the sprite x degrees clockwise
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number |
Example
sprite.turn_left(45)
(static) turn_right(degrees)
turn_right() animates a rotation of the sprite x degrees clockwise. If x is negative, it animates a rotation of the sprite x degrees counterclockwise
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number |
Example
sprite.turn_right(45)
(static) velx() → {number}
velx() returns the velocity of the sprite in the x direction
Returns:
velocity of the sprite in the x direction
- Type
- number
Example
sprite.velx()
(static) vely() → {number}
vely() returns the velocity of the sprite in the y direction
Returns:
velocity of the sprite in the y direction
- Type
- number
Example
sprite.vely()
(static) wait(seconds)
wait() causes a sprite to wait a certain amount of seconds before completing the next action.
Parameters:
Name | Type | Description |
---|---|---|
seconds |
number |
Example
sprite.wait(3)
(static) x() → {number}
x() returns the x-coordinate of the sprite
Returns:
x-coordinate of the sprite
- Type
- number
Example
sprite.x()
(static) y() → {number}
y() returns the y-coordinate of the sprite
Returns:
y-coordinate of the sprite
- Type
- number
Example
sprite.y()