public final class GameObjectManager extends java.lang.Object implements IMessageClient, GameView.IRedrawService, GameView.IGameLogicService
One instance of this class is created by the main game Activity and provided to the
GameView
at startup time.
Modifier and Type | Field and Description |
---|---|
MessageBus |
mBus
An instance of the
MessageBus that can be used to send messages, assuming we start using
that feature again. |
Constructor and Description |
---|
GameObjectManager(MessageBus mbus,
android.content.res.Resources res)
Called by the game's main Activity to set up all the game logic.
|
Modifier and Type | Method and Description |
---|---|
void |
addObject(GameObject obj)
Adds a
GameObject or a subclass into the list of objects being managed. |
void |
draw(android.graphics.Canvas canvas)
Called by the game engine thread to redraw all game objects.
|
GameObject |
getObjectByName(java.lang.String name)
Look up the first object that was registered with name
name |
java.util.List<GameObject> |
getObjectsMatching(java.lang.String prefix)
Return a list of all game objects whose names start with the given prefix.
|
android.content.res.Resources |
getResources()
Returns the cached resources object.
|
float |
getWorldScreenHeight()
Get the currently-configured world height in world units
|
float |
getWorldScreenWidth()
Get the currently-configured world width in world units
|
void |
handleMessage(Message msg)
Ignore this for now.
|
boolean |
isFullyOffScreen(GameObject obj)
Returns true if the object is entirely outside the boundaries of the screen
at the object's current location.
|
boolean |
isFullyOnScreen(GameObject obj)
Returns true if the game object is entirely within the boundaries of the screen at
the object's current location.
|
void |
onMotionEvent(GameView.UIEvent e)
Called by the game engine thread as events arrive.
|
void |
setLevel(GameLevel level)
Requests the game engine to move to a different game level after the
current update/draw cycle is complete.
|
void |
setScene(Scene scene)
Set the scene to be used as a background starting on the next draw() cycle.
|
void |
setWorldScreenSize(float width,
float height)
Sets the width and height of the game world in arbitrary units.
|
void |
update(int millis)
Called by the game engine thread to update all game objects.
|
public MessageBus mBus
MessageBus
that can be used to send messages, assuming we start using
that feature again.public GameObjectManager(MessageBus mbus, android.content.res.Resources res)
mbus
- MessageBus
for passing messages between game objects and infrastructureres
- pointer to the resources for this Activity so we can make them accesible to
things that need them, in particular Sprite
and
BackgroundImageScene
public void setLevel(GameLevel level)
level
- a subclass of GameLevel
customized for your gamepublic android.content.res.Resources getResources()
public void addObject(GameObject obj)
GameObject
or a subclass into the list of objects being managed.
Objects in this list will have their update() and draw() routines called at regular intervals, and will receive UI events (taps, swipes) that are within their boundary.
obj
- a GameObject
or derived class to managepublic GameObject getObjectByName(java.lang.String name)
name
name
- the name of the object to search fornull
.public java.util.List<GameObject> getObjectsMatching(java.lang.String prefix)
For example, if you register game objects named orc1, orc2, orc3 then you could get a list of these objects by calling with prefix = "orc".
prefix
- the string to match against the object names.List
containing zero or more game objects.public void setScene(Scene scene)
If you want the background to just be a solid color, pass in an instance of
SolidColorScene
.
If you want the background to be an image, pass in an instance of
BackgroundImageScene
.
scene
- a subclass of Scene
of the desired typepublic void setWorldScreenSize(float width, float height)
This method should be called once at the start of a level to set the desired size of the world for that level. Changing the world size after the level is running has undefined behavior.
If you don't call this method, the default will be whatever size was configured by the previous level, or 1600x900 if it was never called. 1600x900 is a good choice if you don't have a reason to do otherwise.
width
- width of the world in unitsheight
- height of the world in unitspublic void handleMessage(Message msg)
handleMessage
in interface IMessageClient
msg
- public void onMotionEvent(GameView.UIEvent e)
onMotionEvent
in interface GameView.IGameLogicService
e
- the event to deliver.public void draw(android.graphics.Canvas canvas)
draw
in interface GameView.IRedrawService
canvas
- the current canvas object associated with our SurfaceView
public void update(int millis)
update
in interface GameView.IGameLogicService
millis
- number of milliseconds since the last world update.public boolean isFullyOnScreen(GameObject obj)
obj
- the game object to check for on-screen-nesstrue
if the object is entirely on-screenpublic boolean isFullyOffScreen(GameObject obj)
obj
- the game object to check for off-screen-nesstrue
if the object is entirely off-screenpublic float getWorldScreenWidth()
public float getWorldScreenHeight()