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

JavaScript Introducing JavaScript Let's Make a Game Doing Things With Functions

Mykela Brown
Mykela Brown
522 Points

Hello, I have been trying to add more coins and more platforms. So far I have been able to make 7 coins and 6 platforms.

This is my code. items = game.add.physicsGroup(); createItem(375, 400, 'coin'); createItem(575, 500, 'coin'); createItem(225, 500, 'coin'); createItem(200, 450, 'coin'); createItem(650, 469, 'coin'); createItem(200, 100, 'coin'); createItem(390, 209, 'coin'); createItem(650, 469, 'coin'); createItem(550, 689, 'coin');
}

// add platforms to the game function addPlatforms() { platforms = game.add.physicsGroup(); platforms.create(550, 689, 'platform'); platforms.create(375, 670, 'platform'); platforms.create(375, 459, 'platform'); platforms.create(650, 469, 'platform'); platforms.create(550, 659, 'platform'); platforms.create(400, 350, 'platform'); platforms.create(390, 209, 'platform'); platforms.create(575, 100, 'platform'); platforms.create(200, 100, 'platform'); platforms.setAll('body.immovable', true); }

I believe my coordinates may be the issue but I don't know why certain coins and platforms won't show up? Also, is there an easier way to solve the coordinate issue instead of experimenting with the numbers? I'm also having an issue with matching the platform with a coin. Thank you for the help.

1 Answer

Steven Parker
Steven Parker
229,670 Points

I don't know if the game engine rejects images with overlapping coordinates entirely; but even if not, one would obscure the other.

A definitive way to resolve this issue is to create a map or grid where you add the width and height dimensions to the locations of each object to determine the complete range of pixels that it will occupy. Then you can make certain that no two objects overlap at any point.

If you need more assistance, it would be helpful to be able to replicate the issue. See this video about sharing a snapshot of your workspace.