My student wants the baby elephant to descend down and to the left in front of the blue rectangle, like it’s going into a pond.
What actually happens:
The baby elephant descends down and to the left, but goes behind the rectangle.
What I’ve tried:
I tried moving the blue rectangle above the draw loop (predictably it disappears). I tried moving it below the lines that call the baby elephant to move. I tried placing the rectangle below the drawSprites block. I also tried placing it below the draw loop. None of it makes the elephant move on top of the rectangle.
My student’s code:
var background = createSprite(200,200);
background.setAnimation(“background”);
var elephant1 = createSprite(350,300);
elephant1.setAnimation(“elephant1”);
elephant1.scale = 0.4;
var elephant2 = createSprite(75,300);
elephant2.setAnimation(“elephant2”);
elephant2.scale = 0.6;
var babyelephant = createSprite(325,325);
babyelephant.setAnimation(“babyelephant”);
babyelephant.scale = 0.2;
function draw(){
fill(“skyblue”);
rect(100,350,200,100);
drawSprites();
fill(“skyblue”);
rect(100,350,200,100);
babyelephant.x = babyelephant.x - 1;
babyelephant.y = babyelephant.y + 0.5;
fill(“yellow”);
ellipse(350,50,100,100);
fill(“black”);
textSize(25);
text(“WOOOOH!!!”,150,325);
textSize(25);
text(“That’s what \n I paid for!”,250,200);
text(“HAHAHA!!!”,75,200);
Similar to that issue, I have another student that wants sprites to move on top of a shape, but place the shape in front of a background sprite. The shape (an orange square) won’t appear unless it’s on top of the moving sprites. He wants it underneath them.
What’s happening here is that your background is a sprite along with the elephants. You are wanting the rectangle to be above the background, but behind the elephant but since all the sprites are drawn at once, there’s no way to draw the rectangle in between drawing the background and the elephant.
The solution is to create the pond as a custom sprite rather than as a rectangle. Your student could Make a sprite and draw a rectangle or other shape as the pond and then create it with the other sprites to get the desired effect.
I knew they could make the pond into a sprite, but they’re trying to meet the requirements of the Lesson 14 project (2 sprites, 2 shapes, 2 text, animation). If the pond becomes a sprite, they won’t have a shape.
Is there any way to do it while keeping the shape a shape?
The only other way I can think of is to use the undocumented command drawsprite() and draw each sprite one at a time which is neither elegant or practical especially if the scene were to get larger. The other option is to not use a sprite for the background. Then, the shape could be drawn after the sprites are drawn, but even that would be problematic because the elephant would have to be drawn individually after the shape with drawsprite(elephant).
Hopefully this makes sense, but in reality the best solution is to turn the pond into a sprite.
Thanks for your help! I’ve got a few kids who keep “pushing the envelope” and trying to do more than the levels require and I don’t want to discourage them, but finding ways to sort of work around what they have available in the current lesson (and still meet the requirements of the project) has been a (fun) challenge!
I found that I frequently had to remind students that each level is usually a “small bite” & that they need to really read the instructions for each level. They would often do 4 or 5 steps then complain that the level was too hard.