0% found this document useful (0 votes)
22 views17 pages

Javascript+ +sprites+ (APCSP) +

A sprite in JavaScript is an object that has properties for location, movement, and appearance, and can be animated by changing its image. Sprites are created using a specific block in Code.org, which treats them like variables and allows for the use of properties and functions. To customize a sprite, users can set its animation and modify its properties after uploading the desired image.

Uploaded by

terrarian1299ooo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views17 pages

Javascript+ +sprites+ (APCSP) +

A sprite in JavaScript is an object that has properties for location, movement, and appearance, and can be animated by changing its image. Sprites are created using a specific block in Code.org, which treats them like variables and allows for the use of properties and functions. To customize a sprite, users can set its animation and modify its properties after uploading the desired image.

Uploaded by

terrarian1299ooo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

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

You might also like