Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Siddhant 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,664 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,664 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?