|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.Observable
com.transmote.nest.events.EventDispatcher
com.transmote.nest.NestSprite
com.transmote.nest.NestSpriteContainer
public class NestSpriteContainer
A NestSpriteContainer sits at the top of the Nest display list. All NestSprite instances visible on-screen are descendants of a NestSpriteContainer. This means that traversal up the display list from a NestSprite instance's parent, to its parent, and so on, will ultimately reach the NestSpriteContainer.
updateDisplayList() should be called every frame by application code; updateDisplayList()
then travels down the display list, from NestSprite to NestSprite, calling NestSprite.update(PApplet)
on each, and then NestSprite.draw(PApplet) on each.
NestSpriteContainer acts as the conduit for input events (such as MouseEvents and KeyEvents)
between PApplet and application code (NestSprite instances). Input events are dispatched
by PApplet and handled by NestSpriteContainer, then sent down through the display list.
See Event for more detail on the event flow.
If the developer wishes to eliminate the display list at runtime,
call dispose().
/*
* DisplayList
*
* Nest provides a simple display list architecture
* modeled on the ActionScript 3.0 display list.
*
* A NestSpriteContainer lives at the top of a display list.
* Adding NestSprite children to it will subject them to the
* same transformations (translation, rotation, scale)
* applied to their parents.
*
* Press the up and down arrow keys and the backspace key
* to add and remove NestSprite children.
*/
import com.transmote.nest.*;
import com.transmote.nest.events.*;
NestSpriteContainer spriteContainer;
void setup () {
size(400, 400);
// create a NestSpriteContainer to hold all other NestSprites,
// and position it at the vertical center of the screen.
spriteContainer = new NestSpriteContainer(this);
spriteContainer.y = 0.5 * height;
}
void draw () {
background(0);
// calling NestSpriteContainer.update() will automatically
// loop through all its descendant NestSprite instances,
// call update() on each, and then call draw() on each.
spriteContainer.updateDisplayList();
}
void keyPressed () {
switch (keyCode) {
case 38:
// UP pressed
addSprite();
break;
case 40:
// DOWN pressed
removeSprite();
break;
case 8:
// delete pressed
removeAllSprites();
break;
}
}
void addSprite () {
// add a new SineSprite to the front of the display list.
SineSprite sprite = new SineSprite();
sprite.x = 10 + spriteContainer.numChildren() * 10;
spriteContainer.addChild(sprite);
}
void removeSprite () {
// remove the front-most SineSprite from the display list.
if (spriteContainer.numChildren() > 0) {
spriteContainer.removeChild(spriteContainer.numChildren()-1);
}
}
void removeAllSprites () {
// remove all SineSprites from the display list.
while (spriteContainer.numChildren() > 0) {
spriteContainer.removeChild(spriteContainer.numChildren()-1);
}
}
| Field Summary |
|---|
| Fields inherited from class com.transmote.nest.NestSprite |
|---|
blendMode, boundsLeft, boundsTop, handleCaptureEvents, height, inFront, inputChildren, inputEnabled, NO_BLEND_MODE, rotationX, rotationY, rotationZ, scaleX, scaleY, scaleZ, visible, width, x, y, z |
| Constructor Summary | |
|---|---|
NestSpriteContainer(PApplet p)
The NestSpriteContainer to be the top of the display list. |
|
| Method Summary | |
|---|---|
void |
dispose()
Frees up this NestSpriteContainer, and all child NestSprites, for garbage collection. |
void |
keyEvent(processing.event.KeyEvent pEvent)
|
void |
mouseEvent(processing.event.MouseEvent pEvent)
|
void |
update()
Deprecated. |
void |
updateDisplayList()
Updates the Nest display list: Calls update() on self and all NestSprite descendants, then calls draw() on self and all NestSprite descendants. |
| Methods inherited from class com.transmote.nest.NestSprite |
|---|
addChild, addChild, bounds, dispatchEvent, dispose, getChildAt, getChildIndex, globalToLocal, hitTest, hitTest, isDisposed, localToGlobal, mousePt, mouseX, mouseY, numChildren, pApplet, parent, removeChild, removeChild, renderer, screenPt, screenX, screenY, setBounds, setBounds, setChildIndex, setDraw, setDraw, setRenderer, setRenderer, setUpdate, setUpdate, swapChildren, swapChildren |
| Methods inherited from class com.transmote.nest.events.EventDispatcher |
|---|
addObserver, deleteObserver, dispatchEvent, owner, update |
| Methods inherited from class java.util.Observable |
|---|
countObservers, deleteObservers, hasChanged, notifyObservers, notifyObservers |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public NestSpriteContainer(PApplet p)
p - A reference to the PApplet running this Processing sketch.| Method Detail |
|---|
public void updateDisplayList()
@Deprecated public void update()
public void dispose()
dispose in class NestSpritepublic void mouseEvent(processing.event.MouseEvent pEvent)
public void keyEvent(processing.event.KeyEvent pEvent)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||