Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialStacy Chairez
178 PointsHow to create a lifeCounter
After this last video, the instructor suggests we create a lifeCounter that will decrease every time the player touches the poison. How do I do this? I used createItem to create a lifeCounter, but doesn't that somehow need to be linked to a png file so the game knows what to do? I also wrote var lives =3 under the define variables function, but nothing has changed when i view the game. I know I'm missing something here. Can I get some direction on this please?
Daniyell Augusta
Courses Plus Student 495 PointsHi Stacy,
livesText = game.add.text(685, 16, "LIVES: " + lives, { font: "24px Arial", fill: "white" });
Use this instead of createItem. You don't need a graphic, it is just a text. This line gives us the text "LIVES" on the top right.
1 Answer
Steven Parker
231,275 PointsThis was the second task of the final code challenge. Take a look at the code in the challenge.
Daniyell Augusta
Courses Plus Student 495 PointsDaniyell Augusta
Courses Plus Student 495 PointsHowever, I couldn't figure out yet how to actually substract the lives when hitting the poison.
Isn't this the right code (like described in the code challenge)?
Hmm