Unit 3 Lesson 12 - Sprite Movement

Hi everyone!

I tried using sprite.scale = sprite.scale - 0.1 to decrease the size of a sprite using Counter Pattern but it seems to grow larger.

Also tried sprite.height = sprite.height - 1 & sprite.width = sprite.width - 1, but it shrinks to a certain size and then grows again.

Any idea how I can shrink sprites using Counter Pattern?

Thanks!

@clcheah,

If you can click on the share link and share your code with us, we can take a look to make sure, but I think I know what you are describing. When a sprite reaches a size of 0, but you are still asking it to get smaller, it behaves a little unexpectedly by getting larger. It’s actually taking on a negative size which on screen appears to show it getting larger. It’s actually flipping inside out if you look closely.

To get a sprite to disappear when the size is 0, you need to use a conditional block where you hide the sprite when the size is < 0.

If you are struggling with it in one of your projects, feel free to click on the share link and send us that link and we can look closer at it.

Best of luck!

Mike

Hi @mwood

Thanks for getting back to me, you are spot on about what happened when the code was run. Great suggestion using conditionals, we will do that in Lesson 14.

Below is the code used when I was demonstrating Counter Patterns to students.

Thanks again!

Best regards,
Clement

//create mouse
var mouse = createSprite(50, 50);

//create tiger
var tiger = createSprite(300,300);

//set mouse speed
var mouseSpeed = 2;

//set tiger speed
var tigerSpeed = 2;

//set mouse properties
mouse.setAnimation(“mouse”);
mouse.scale = 0.2;
mouse.rotation = -45;

//set tiger properties
tiger.setAnimation(“tiger”);
tiger.scale = 0.3;

//draw mouse
function draw() {
background(“lightgreen”);

mouse.x = mouse.x + mouseSpeed;
mouse.y = mouse.y + mouseSpeed;
mouse.rotation = mouse.rotation - 1;

tiger.x = tiger.x - tigerSpeed;
tiger.y = tiger.y - tigerSpeed;
tiger.scale = tiger.scale - 0.1;
//tiger.height = tiger.height - 2;
//tiger.width = tiger.width - 2;

drawSprites();
}

1 Like