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 trialSiddhant Gandhi
Full Stack JavaScript Techdegree Student 379 PointsWhy is the syntax for function addItems and function addPlatforms different when they are both doing the same thing?
[Contd.] Which is adding graphics to the game? (to add a coin, we are using createItem, and to add platform we are using platform.create) Is it because to add a coin we are using a different function as it is a collectable item which has to disappear when collected?
2 Answers
KRIS NIKOLAISEN
54,972 PointscreateItem contains similar snytax
var item = items.create(left, top, image);
but also includes code to add the spin animation to coin
item.animations.add('spin');
item.animations.play('spin', 10, true);
KRIS NIKOLAISEN
54,972 PointsYes. It looks like animations are set individually and the function is used to avoid repeating three lines of code for each item. Whereas after creation the platforms use a setAll method to fix the position of all platforms.
For fun comment out the following and see what happens
platforms.setAll('body.immovable', true);
Siddhant Gandhi
Full Stack JavaScript Techdegree Student 379 PointsSiddhant Gandhi
Full Stack JavaScript Techdegree Student 379 PointsOh so is that why we are using function createItems for coins, poison, and stars and just platform.create for creating platforms?