Unit 3, Lesson 17, Help with Animation

I need some help here. I have a student who would like to have a different animation depending on where the mouse is on the screen. That said, all we have learned at this point is World.mouseX or Y and where it is in a general area on the screen (i.e. World.mouseX<200. He would like to have it be a specific location on the screen, for example, x position between 50-60 and y position between 100-110. How could he do this? Thanks for any suggestions!

Greetings @msima,

If I’m understanding correctly you wish to create invisible boundaries for the player if that’s the case i recommend setting up listeners that’ll test as such

An Example has been provided bellow

// Initialize the sprite
var sprite = createSprite(50, 100);
// start the main loop here
function draw() {
 if(keyWentDown("up") && sprite.y > 100 {
  sprite.y -= 5;
 } else if (sprite.y < 100){
  sprite.y = 100;
 }
 if(keyWentDown("down") && sprite.y < 110) {
  sprite.y += 5;
 } else if (sprite.y > 110) {
  sprite.y = 110;
 }
drawSprites();
}

with this i think you should be able to determine what else you need to make for the horizontal direction to work if you have any further questions feel free to ask

hope this helps!

1 Like