Android Game Programming by John Horton

Android Game Programming by John Horton

Author:John Horton
Language: eng
Format: epub
Publisher: Packt Publishing


Then, we add a method to initialize the hitbox and a method so that we can grab a copy of it when needed. Add these two methods to GameObject:

public void setRectHitbox() { rectHitbox.setTop(worldLocation.y); rectHitbox.setLeft(worldLocation.x); rectHitbox.setBottom(worldLocation.y + height); rectHitbox.setRight(worldLocation.x + width); } RectHitbox getHitbox(){ return rectHitbox; }

Now for our Grass object, we add a call to setRectHitbox() and then we can start bumping into it. Add this one line of highlighted code at the very end of the Grass class's constructor. It is important that the call to setRectHitbox() comes after the call to setWorldLocation() otherwise the hitbox won't be wrapped around the block of grass.

// Where does the tile start // X and y locations from constructor parameters setWorldLocation(worldStartX, worldStartY, 0); setRectHitbox(); }// End of Grass constructor



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.