JavaScript Introducing JavaScript Finishing the Game Adding New Graphics

Siddhant Gandhi
Siddhant Gandhi
Full Stack JavaScript Techdegree Student 278 Points

Why 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
PRO
KRIS NIKOLAISEN
Pro Student 35,790 Points

createItem 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);
Siddhant Gandhi
Siddhant Gandhi
Full Stack JavaScript Techdegree Student 278 Points

Oh so is that why we are using function createItems for coins, poison, and stars and just platform.create for creating platforms?

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 35,790 Points

Yes. 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);