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 trial
melissa brown
4,670 Pointswhich method: when something hits do this?
Hi im trying to achieve an effect when the blue fireball reaches the dragon. the dragon will explode. i tried first adding the explode effect when you click on the dragon, but i cant get it to work. then i wanted to add when the blue fireball arrives at the dragon, the dragon should explode. what method would i used for when the blue fireball arrives then do something? any ideas.
1 Answer
miikis
44,957 PointsHa that's tight Melissa!
So there's a typo on line 55 & 56 of your JavaScript ("explosion" is supposed to be ".explosion") ... that's why clicking the dragon isn't working.
As for making the dragon explode, I can think of two ways off the top of my head:
- You could use a setTimeout function, that calls an explode() function after like 1000ms, or however long the length of the fireball animation is.
- You could also get the x and y position of the dragon and use a conditional statement ... so like "if fireball's x-position is greater than or equal to dragon's x-position, dragon should explode." That second option is probably the most useful.
Good luck :)