-
Notifications
You must be signed in to change notification settings - Fork 0
Using Game Objects
GameObject is the vital class of a game, it represent an entity (monster, player), an image, an intro, a video, etc. and much more
Let's add a rectangle to our test game:
New Imports:
import org.powerhigh.objects.Rectangle;
import org.powerhigh.utils.Color;At the end of init()
win.setViewportManager(new SizedViewport(500, 400));
Rectangle rect = new Rectangle(100, 100, 100, 100, Color.YELLOW);
win.add(rect);Here is the result:
How it work ?
We create a new rectangle called "rect", at position 100, 100 and with a size of 100x100px then it is added to the window container. win.setViewportManager(...) is used the object that manage what the users view. It got added to not render out-of-screen objects in nothing. And to have a game with same field of view for everyone.
First of all, you should have a texture:
Texture tex = TextureLoader.getTexture("MyImage.png");The image must be placed at project root (not "src"),example on eclipse below
And just make a new Sprite with the Texture as argument.
Example:
Texture tex = TextureLoader.getTexture("MyImage.png");
Sprite sprite = new Sprite(tex);And of course, don't forget the win.add!
If you did all correctly you should get (Note: the result again uses SizedViewport, you can find more details here: Viewport Managers)