HTML and CSS Reference
In-Depth Information
This
type
value will need to be used in a switch statement inside the
renderParticles()
function to determine which of the four tiles to render for a given particle. Let's examine this
function now:
function
function
renderParticles
() {
var
var
tempParticle
=
{};
var
var
particleLength
=
particles
.
length
-
1
;
for
for
(
var
var
particleCtr
=
particleLength
;
particleCtr
>=
0
;
particleCtr
--
){
tempParticle
=
particles
[
particleCtr
];
context
.
save
();
//save current state in stack
var
var
tile
;
console
.
log
(
"part type="
+
tempParticle
.
type
)
switch
switch
(
tempParticle
.
type
){
case
case
0
:
// saucer
tile
=
0
;
break
break
;
case
case
1
:
//large rock
tile
=
2
break
break
;
case
case
2
:
//medium rock
tile
=
3
;
break
break
;
case
case
3
:
//small rock
tile
=
0
;
break
break
;
case
case
4
:
//player
tile
=
1
;
break
break
;
}
var
var
sourceX
=
Math
.
floor
(
tile
%
4
)
*
tempParticle
.
width
;
var
var
sourceY
=
Math
.
floor
(
tile
/
4
)
*
tempParticle
.
height
;
context
.
drawImage
(
particleTiles
,
sourceX
,
sourceY
,
tempParticle
.
width
,
tempParticle
.
height
,
tempParticle
.
x
,
tempParticle
.
y
,
tempParticle
.
width
,
tempParticle
.
height
);
context
.
restore
();
//pop old state on to screen
}