Game Development Reference
In-Depth Information
The gold coin uses the collected variable to store its current state of visibility. The
render() method will always check the collected state to decide whether the object
should be rendered or not. The getScore() method returns the item's score that the
player will receive to collect it. The bounding box bounds are set to the exact same
size as its dimension inside the game world.
Creating the feather object
The feather game object is very similar to the gold coin. It consists of only one
image and is a collectible item that will turn invisible when it is collected by
the player's character.
Create a new file for the Feather class and add the following code:
package com.packtpub.libgdx.canyonbunny.game.objects;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.packtpub.libgdx.canyonbunny.game.Assets;
public class Feather extends AbstractGameObject {
private TextureRegion regFeather;
public boolean collected;
public Feather () {
init();
}
private void init () {
dimension.set(0.5f, 0.5f);
regFeather = Assets.instance.feather.feather;
// Set bounding box for collision detection
 
Search WWH ::




Custom Search