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.

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
217,569 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.