-
Notifications
You must be signed in to change notification settings - Fork 0
Custom GameObjects
ImTallone edited this page Mar 25, 2019
·
8 revisions
Extending GameObjects allow you to make an entity system (players, monsters), items, GUI, etc.
For example, here is a TestObject drawing a red circle:
package org.mygame;
import org.powerhigh.objects.GameObject;
import org.powerhigh.graphics.Interface;
import org.powerhigh.graphics.Drawer;
import org.powerhigh.utils.Color;
public class TestObject extends GameObject {
@Override
public void paint(Drawer drawer, Interface source) {
drawer.setColor(Color.RED);
drawer.fillOval(x, y, width, height);
}
}You might want to make it draw an item, for example by using other Graphics methods, like g.drawTexture(...)
First, to show an image, your item can extends the "Sprite" class for having the job easier
public class Item extends Sprite {
public Item() {
try {
super(TextureLoader.getTexture("sword.png"));
setWidth(64);
setHeight(64);
} catch (Exception e) {
super();
}
}
}The Sprite class will do the rest, it will render the texture, Sprite constructor can also be used with Animations.
You can also directly draw the image and setup the variables by using Drawer methods.