28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16 ■ Collision Detection: Creating SVG Polygons for the Game Actors and Writing Code to Detect Collision<br />

Figure 16-23. Fine-tune your vertex placement for the collision polygon in the PhysicsEditor, then select your Exporter<br />

The closer you can get the collision polygon to the outline of the sprite, optimally you would want to put it right<br />

on top of the anti-aliasing that is on the pixel-edge between the sprite pixels and the transparency, or even right inside<br />

of the anti-aliasing if you want a more challenging game play. Ultimately, your collision polygons will have to be<br />

tweaked during your game development and game testing cycles, so that you get the most realistic result during your<br />

game play. If you’re developing for powerful platforms such as game consoles, you can add data points to the collision<br />

polygon, and if you’re developing for single or dual processor platforms, such as HTML5 phones or iTVs, use less data.<br />

Replacing Dummy Collision Data: InvinciBagel.java<br />

Next, let’s make some changes to your <strong>Java</strong> code in the InvinciBagel.java class, so that you are actually using this<br />

highly optimized collision polygon data that we just developed during this chapter. We will use the data set that has<br />

only 15 data points, so that we can see all of our collision polygon data in our NetBeans 8.0 code editing pane. As you<br />

can see in Figure 16-24, we will need to put the Bagel() constructor method call on three different lines: one for the<br />

iBagel = new Bagel(this) part of the instantiation, another for the collision polygon SVG data String object, and<br />

another for the xLocation, yLocation and Image object List. We will also be using our knowledge of SVG commands,<br />

which we learned from Table 16-1, to create the collision polygon data for our tileable brick elements. We will be using<br />

these brick “Prop” elements to develop our collision detection <strong>Java</strong> code later on in the chapter. We will create these<br />

simpler collision polygons using only our brains, by implementing numeric logic that relates to the resolution of the<br />

brick image, and where the corner pixel locations would be in X,Y coordinate space, in conjunction with the SVG path<br />

drawing commands that we learned about in Table 16-1. You are becoming quite a game development professional!<br />

www.it-ebooks.info<br />

365

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!