Javascript
Sprites
A sprite is an object on the screen
with properties that describe its
location, movement, and appearance.
A sprite can be animated by quickly
changing its image.
This picture is called a sprite sheet.
The image is part of the sprite, but
a sprite is more than just an image.
In Javascript, sprites are objects.
An object is a special
type of container that
has properties and
functions inside.
Think of an object in real life, like a car.
A car has properties…
car.model
car.year
car.topSpeed
car.color
…and functions.
car.drive(speed)
car.stop()
Properties are just variables that belong
to the object.
r t y
pe
Pro
They are accessed
using dot syntax.
myObject.myProperty
Here are some sprite properties from
Code.org…
Some objects have built-in functions…
t i o n
Fu nc
Functions have
parenthesis after the
function name.
myObject.myFunction()
Here are some sprite functions from
Code.org…
In Code.org, we use this block to declare
(or create) our sprites…
Generally, we do this at the
top of the code, not in the
Draw Loop. Why?
In Code.org, we use this block to declare
(or create) our sprites…
Notice it treats the sprite
object just like a variable,
since it is also a container
that holds values.
Give the sprite a unique name!
In Code.org, we use this block to declare
(or create) our sprites…
It uses a function with
position parameters to
simplify the creation of the
sprite for you.
Your sprite will show up as a gray square
until you set you use the setAnimation()
block to give it an image.
Make sure you have already uploaded
the image in the Animation tab.
Change your sprites by using their
properties:
THE
END