In this project the student wants the “boi” sprite to grow and grow until it is larger than scale 1. Then it turns in to “blood.” Then he wants its scale to shrink and shrink. Why won’t the “boi” (now blood) shrink & shrink?!
if (boi.scale > 0.1) {
boi.setAnimation(“boi”);
boi.scale = boi.scale + 0.01;
}
if (boi.scale > 1) {
boi.setAnimation(“blood”);
boi.scale = boi.scale - 0.01;
When you get to boi.scale>1 it does start to decrease BUT the boi.scale>0.1 also is running therefore it is like + 0.01 and -0.01 at the same time which means no size change.
Does the student want it to keep going back and forth between animations? This would affect how to debug it.
When the boi sprite turns into blood, it’s scale is bigger than 1, but it is also bigger than 0.1.
That means that even when if boi’s scale is higher than 1 both blocks of code inside the if statements are going to be executed.
How to fix:
- Remove everything related to the variable blood. In other words, remove this part of the code:
Then, create a variable called turnedIntoBlood at the beginning of the code and set it to false.
Then, delete all of this:
Then in function draw put this:
if(boi.scale > 1){
turnedIntoBlood = true
}
if(turnedIntoBlood == true){
boi.setAnimation(“blood”)
boi.scale -= 0.01
}
if(turnedIntoBlood == false){
boi.setAnimation(“boi”)
boi.scale += 0.01
}
This should work, however there is a bug/glitch in GameLab where when sprite’s scale would be less than zero they would flip. To stop that you can add this at the end of function draw:
if(boi.scale <= 0){
boi.visible = false;
}
I hope this helps!