Lesson 13 Activity 2


#1

I am having some difficulty with this activity. I can set the animation to follow the mouse with a World.mouseX and World.mouseY, but the program draws multiple versions of the bee. When I try and copy the example information and use game.mouseX and game.mouseY I am told that the “game” identifier has not been declared.

Please advise.


#2

When it is drawing multiple bees, was your “Background” block inside the draw loop? If it isn’t, it isn’t being redrawn after each bee so each move of the mouse will draw a new bee and not a new background. When you put the draw background inside the draw loop, it should redraw the background before checking for the new Mouse X and Mouse Y values.


#3

Ahh! Exactly right. Thank you.

How about the fact that the Example Solution specs out “Game” instead of “World”…should that be changed?


#4

So, I’m not a Javascript expert, but it looks like in their programming exemplar, they have used a class called Game rather than world. In our environment (and the students’ environment), they are supposed to use world as the class. Anyone more knowledgable about Javascript care to comment? This may be another “bug” to point out. I hadn’t looked at the exemplar solution before seeing your question and hadn’t noticed that.


#5

This is actually a remnant from an older version of Game Lab, when the global object was Game. We switched the global object to World to encourage students to think more broadly about what they might make. We still support Game for backwards compatibility. I’ll update that exemplar and poke around to see if we have other old ones that need updated.


#6

The “game” confused me up too… this is the solution I got

var bee = createSprite(200, 200);
bee.setAnimation(“bee”);

World.frameRate = 20;

function draw(){
background(“lightblue”);

bee.x = randomNumber(World.mouseX - 50, World.mouseX + 50);
bee.y = randomNumber(World.mouseY - 50, World.mouseY + 50);

drawSprites();
}


#7

@mary.ryan

Your solution is fun because you get a little bit of random movement going but the bee still follows the movement of the mouse.


#8

This helped! thank You!