Sprite.scale counter pattern working incorrectly

Unit 3, Lesson 9, Level 14 and 15.

When my students try to use the .scale counter pattern with a - to make their sprites increasingly smaller, it has been making them much bigger very fast even when using a 1.

In addition to the correct format of:
sprite.scale = sprite.scale - 1
we have also tried
sprite.scale = sprite.scale + -1
sprite.scale = sprite.scale + 1
sprite.scale + sprite.scale - -1

Each time it jumps to a much bigger size. I don’t have a student example to link to, because they have all taken out those counter patterns as is ruins their animation. Here is an example on my own account : https://studio.code.org/projects/gamelab/zaOHH1Zg-oku5IfzVlW5_TyjLJRxTslbTrEsQ55EWGw

Amy,

On GameLab you can “mouse over” any of the block and get to the documentation by clicking on “See examples”. From that page:

"Shrink or grow a sprite keeping the height to width ratio the same.

For example, a value of 2 will be make the sprite twice as big and a value of 0.5 will make the sprite half as big. Scaling up may make images blurry. The scale should always be a positive number.

The default scale is 1. All sprite properties can be both accessed and updated."

So you might want to start with smaller numbers (0.05) to increase by rather than 1. Example: green.scale = green.scale - 0.05;. I played around with the project you shared and it grew much slower, but I don’t know exactly what you’re looking for.

Try that out and let us know if it worked and if you have further questions!
Brad

1 Like

Hi Brad - I have a student that is trying to make a ‘beating’ heart.
It is not changing in size at all.
This is her code:
var space = false;
var heart = createSprite(200, 200);
heart.setAnimation(“Heart-7th.png_1”);
textFont(“Arial”);
textSize(20);
heart.scale = 0.3;
drawSprites();
function draw() {
//background
background(“black”);
drawSprites();
if (keyDown (“space”)) {
space = true;
}
if (space===true) {
//brokenheart code
background(“black”);
heart.setAnimation(“broken heart-7th.png_1”);
heart.scale = 0.25;
heart.x = randomNumber(198, 202);
drawSprites();
fill(“white”);
text(“Its not me it’s”, 146, 185);
text(“you-cya later boo ;)”, 134, 208);
}
if (space===false) {
//heart code
background(“black”);
heart.scale = heart.scale + 2;
heart.scale = heart.scale - 2;
drawSprites();
fill(“white”);
text(“We have our differences”, 97, 160);
text(“and i’m done with them.”, 100, 188);
}
}

This is a bit hard to troubleshoot without having a link to the actual project. If there’s any way you can click on share and get the link to the project, I’m sure we will do a better job of debugging.

Off the top of my head, I am seeing drawSprites() called at least three different times. Normally, it is called once, somewhere inside the draw loop. Depending on where in the code it is called and what else is going on, that could have unintended consequences.

Also, in the 2nd loop, when you have the following code:

heart.scale = heart.scale + 2;
heart.scale = heart.scale - 2;

it would most likely change from large, back to its regular size at a speed faster than the human eye could see, so most likely, it would appear to not change at all.

Hope this gives you some ideas.

Mike