# Sprite.scale counter pattern working incorrectly

**URL:** <https://forum.code.org/t/sprite-scale-counter-pattern-working-incorrectly/26109>\
**Category:** Coding and Debugging Help\
**Tags:** csd-unit-3\
**Created:** [April 4, 2019, 1:10pm UTC](https://forum.code.org/t/sprite-scale-counter-pattern-working-incorrectly/26109 "2019-04-04T13:10:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amy.becker](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@amy.becker](https://forum.code.org/u/amy.becker)\
**Post date:** [April 4, 2019, 1:10pm UTC](https://forum.code.org/t/sprite-scale-counter-pattern-working-incorrectly/26109/1 "2019-04-04T13:10:21Z")

</div>

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](https://studio.code.org/projects/gamelab/zaOHH1Zg-oku5IfzVlW5_TyjLJRxTslbTrEsQ55EWGw)

---

<div class="post-metadata">

**Author:** ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)\
**Post date:** [April 6, 2019, 2:59pm UTC](https://forum.code.org/t/sprite-scale-counter-pattern-working-incorrectly/26109/2 "2019-04-06T14:59:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrea.burgess](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@andrea.burgess](https://forum.code.org/u/andrea.burgess)\
**Post date:** [March 26, 2020, 10:24pm UTC](https://forum.code.org/t/sprite-scale-counter-pattern-working-incorrectly/26109/3 "2020-03-26T22:24:58Z")

</div>

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);  
}  
}

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [March 27, 2020, 3:39am UTC](https://forum.code.org/t/sprite-scale-counter-pattern-working-incorrectly/26109/4 "2020-03-27T03:39:56Z")

</div>

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
