U3 L7 Sprite Scene Animation

I have a student who wants to flip between images to create their animation. They have two lightening bolt images. I can’t figure out why the code isn’t working. Would appreciate the help!

World.frameRate = 80;

noStroke();

background(“black”);

fill(“darkred”);

ellipse(75,150,50,35);

fill(“Black”);

ellipse(75,160,40,30);

fill(“darkred”);

rect(50,150,10,80);

rect(90,150,10,80);

rect(50,180,50,10);

ellipse(132,148,53,25);

rect(105,150,10,60);

ellipse(132,212,53,25);

fill(“Black”);

ellipse(132,202,35,25);

ellipse(132,155,35,25);

fill(“darkred”);

ellipse(200,180,100,100);

fill(“Black”);

rect(150,120,50,200);

ellipse(222,180,45,65);

fill(“darkred”);

rect(200,130,10,100);

ellipse(310,180,100,100);

fill(“Black”);

ellipse(320,180,100,85);

rect(335,130,200,200);

function draw() {

var litter = createSprite(175, 180);

litter.setAnimation(“Litter”);

litter.scale = 0.3;

drawSprites();

}

function draw() {

var lit = createSprite(175, 180);

lit.setAnimation(“Lit”);

lit.scale = 0.3;

drawSprites();

}

Hi @aweedman,

Can you share a link to the project so we can access the code? This makes it easier to debug.

@karenma Here you go! https://studio.code.org/projects/gamelab/gqxuvH0OmClf6Wm4-3O1Arpdp8OUa4wipUTdNKKeUIU

You need the two drawings to happen in the same draw loop. Game Lab takes the last draw loop and only uses that one to create the drawing.

Andrea,

Similar to what Jan said, you need only one draw loop and the images to go back and forth. You can accomplish this by having the spirites visible set to true and false inside of an if/else statement - with the conditional being a timer that changes every second.
Example:
function draw() {
var count = World.seconds;
if(count % 2){
lit.visible = true;
litter.visible = false;
} else {
lit.visible = false;
litter.visible = true;
}
drawSprites();
}

The % is modulo division which looks for the remainder, so the code is true every other second. Hope that make sense and for those about to code - we salute you!

Brad