|
PulpCore | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pulpcore.scene.Scene pulpcore.scene.Scene2D
public class Scene2D
The Scene2D class is a Scene that provdes commonly used features like Sprite management, layer management, Timeline management, and dirty rectangle drawing.
Note the updateScene() method cannot be overridden,
and subclasses should override the update(int)
method instead.
Scene2D and Group
are thread-safe, but in general, Sprites and
Properties are not thread-safe. For multi-threaded apps (for example,
network-enabled apps), use the addEvent(TimelineEvent)
,
addEventAndWait(TimelineEvent)
, invokeLater(Runnable)
, or
invokeAndWait(Runnable)
methods to make sure Sprites and Properties are
modified on the animation thread. For example:
// Called from the network thread. public void receiveNetworkMessage(String message) { // It is safe to add and remove sprites. scene.add(myLabel); // Modify Sprites and properties in the animation thread. scene.invokeLater(new Runnable() { public void run() { myLabel.setText(message); myLabel.visible.set(true); } }); }
Constructor Summary | |
---|---|
Scene2D()
Creates a new Scene2D with one layer and with dirty rectangles enabled. |
Method Summary | |
---|---|
void |
add(Sprite sprite)
Adds a sprite to the main (bottom) layer. |
void |
addEvent(TimelineEvent event)
Adds a TimelineEvent to this Scene2D. |
void |
addEventAndWait(TimelineEvent event)
Adds a TimelineEvent to this Scene2D and returns after the TimelineEvent executes or when this Scene2D is unloaded (whichever comes first). |
void |
addLayer(Group layer)
Adds the specified Group as the top-most layer. |
void |
addTimeline(Timeline timeline)
Adds a Timeline to this Scene2D. |
void |
drawScene(CoreGraphics g)
Draws all of the sprites in this scene. |
int |
getCursor()
Gets the cursor for this Scene. |
Group |
getMainLayer()
Returns the main (bottom) layer. |
int |
getMaxElapsedTime()
Gets the maximum elapsed time used to update this Scene2D. |
int |
getNumSprites()
Returns the total number of sprites in all layers. |
int |
getNumTimelines()
Gets the number of currently animating timelines. |
int |
getNumVisibleSprites()
Returns the total number of visible sprites in all layers. |
void |
hideNotify()
Notifies that this scene has been hidden by another Scene or immediately before a call to stop(). |
void |
invokeAndWait(Runnable runnable)
Causes a runnable to have it's run() method called in the animation thread, and returns after the Runnable executes or when this Scene2D is unloaded (whichever comes first). |
void |
invokeLater(Runnable runnable)
Causes a runnable to have it's run() method called in the animation thread. |
boolean |
isDirtyRectanglesEnabled()
Checks the dirty rectangles are enabled for this Scene2D. |
boolean |
isPaused()
Gets the paused state of this Scene2D. |
void |
redrawNotify()
Notifies that this scene that the Stage or the OS has requested a full redraw. |
void |
remove(Sprite sprite)
Removes a sprite from the main (bottom) layer. |
void |
removeAllTimelines(boolean gracefully)
Removes all timelines from this Scene2D. |
void |
removeLayer(Group layer)
Removes the specified layer. |
void |
removeTimeline(Timeline timeline,
boolean gracefully)
Removes a timeline from this Scene2D. |
void |
setCursor(int cursor)
Sets the default cursor for this Scene. |
void |
setDirtyRectanglesEnabled(boolean dirtyRectanglesEnabled)
Sets the dirty rectangle mode on or off. |
void |
setMaxElapsedTime(int maxElapsedTime)
Sets the maximum elapsed time used to update this Scene2D. |
void |
setPaused(boolean paused)
Sets the paused state of this Scene2D. |
void |
showNotify()
Notifies that this scene has been shown after another Scene is hidden or immediately after a call to start(). |
void |
unload()
Forces all invokeAndWait() and addEventAndWait() calls to return, and removes all layers, sprites, and timelines. |
void |
update(int elapsedTime)
Allows subclasses to check for input, change scenes, etc. |
void |
updateScene(int elapsedTime)
Updates the scene. |
Methods inherited from class pulpcore.scene.Scene |
---|
load, reload |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Scene2D()
Method Detail |
---|
public void setPaused(boolean paused)
public boolean isPaused()
setPaused(boolean)
public final void setCursor(int cursor)
Input
,
getCursor()
public final int getCursor()
Input
,
setCursor(int)
public final void setDirtyRectanglesEnabled(boolean dirtyRectanglesEnabled)
public final boolean isDirtyRectanglesEnabled()
setDirtyRectanglesEnabled(boolean)
public void setMaxElapsedTime(int maxElapsedTime)
If the maximum elapsed time is greater than zero, long pauses between updates (caused by other processes or the garbage collector) effectively slow down the animations rather than create a visible skip in time.
By default, the maximum elapsed time is 100.
public int getMaxElapsedTime()
setMaxElapsedTime(int)
public void addTimeline(Timeline timeline)
This method is safe to call from any thread.
public void removeTimeline(Timeline timeline, boolean gracefully)
gracefully
- if true and the timeline is not looping, the timeline is
fast-forwarded to its end before it is removed.public void removeAllTimelines(boolean gracefully)
gracefully
- if true, all non-looping timelines are
fastforwarded to their end before they are removed.public int getNumTimelines()
public void addEvent(TimelineEvent event)
This method is safe to call from any thread.
public void addEventAndWait(TimelineEvent event)
Error
- if the current thread is the animation thread.public void invokeLater(Runnable runnable)
addEvent(new TimelineEvent(0) { public void run() { runnable.run(); } });
This method is safe to call from any thread.
public void invokeAndWait(Runnable runnable)
addEventAndWait(new TimelineEvent(0) { public void run() { runnable.run(); } });
Error
- if the current thread is the animation thread.public Group getMainLayer()
public void addLayer(Group layer)
public void removeLayer(Group layer)
public int getNumSprites()
public int getNumVisibleSprites()
public void add(Sprite sprite)
public void remove(Sprite sprite)
public void unload()
unload
in class Scene
public void showNotify()
Subclasses that override this method should call super.showNotify();
.
showNotify
in class Scene
public void hideNotify()
Subclasses that override this method should call super.hideNotify();
.
hideNotify
in class Scene
public final void redrawNotify()
Scene
redrawNotify
in class Scene
public final void updateScene(int elapsedTime)
Scene
Stage
while this Scene is active. A scene will typically update
sprites and handle input.
When a Scene is first shown (after a call to showNotify), the elapsedTime is zero.
The Stage starts a synchronized block on this Scene before calling this method and ends
the block after Scene.drawScene(CoreGraphics)
returns.
updateScene
in class Scene
elapsedTime
- time, in milliseconds, since the last call to updateScene().public void update(int elapsedTime)
public void drawScene(CoreGraphics g)
drawScene
in class Scene
g
- the CoreGraphics object to draw to. The CoreGraphics clip is
set to the entire display area.
|
PulpCore | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |