actors - oxygine/oxygine-framework GitHub Wiki
Low level 2D frameworks provides you basic rendering functionality where you're required to draw images each frame manually.
Oxygine isn't low level 2D framework and in addition to this it provides own scene graph.
You could create Sprite, set position and image, attach it to Display (called Stage) and "forget". Sprite would be displayed and updated each frame automatically. You could say to this sprite: "rotate on 360 degrees for 2 seconds 5 times and then remove self".
spSprite sprite = new ColorRectSprite;
sprite->setPosition(300, 300);
sprite->setSize(100, 100);
sprite->attachTo(getStage());
sprite->addTween(Sprite::TweenRotation(2*PI), 2000, 5)->detachWhenDone();
You could create second "child" sprite attached to already created and they would be rotating both:
spSprite child = new ColorRectSprite;
child->setSize(30, 30);
child->attachTo(sprite);
If you want to handle mouse click or touch on "child" subscribe to click event:
void onSpriteClicked(Event*)
{
printf("clicked to child");
}
EventCallback callback = onSpriteClicked;
child->addEventListener(TouchEvent::CLICK, callback );
If you don't want handle the click event on that sprite anymore remove the listener:
child->removeEventListener(TouchEvent::CLICK, callback);
it works only if you create callback with CLOSURE - CLOSURE(someptr, classmethod)
If you do not need child anymore just detach it:
child->detach();
You don't need to call delete because Sprites (Actors) are managed by intrusive smart pointers. It has reference counter inside. Sprite will be freed automatically when you remove the last reference to it.
Oxygine classes with prefix sp are smart pointers. For example spSprite is just typedef:
typedef ox::intrusive_ptr<ox::Sprite> spSprite;
#Actors
Actor is a base class in scene graph. It can be moved, rotated, scaled, animated. Actors can have other actors as children. When a parent is transformed, all its children are transformed as well.
Actor has properties:
- transformation (position, scale, rotation)
- anchor point
- size
- name
- transparency
- list of children
- list of added tweens
- etc.
You would widely use Sprites in your app. Sprite is subclass of Actor. It is using for displaying images and animations.
Polygon is subclass of Sprite. It is used for rendering custom vertices array.
TextField is subclass of Actor. It is used for displaying text.
ProgressBar is subclass of Sprite. It is used for displaying progress.
ColorRectSprite is subclass of Sprite. It is rectangle filled with one color.
ClipRectActor is sublcass of Actor. It is used to clip area with children outside of actor's bound.
Box9Sprite is sublcass of Sprite. It is used to scale the image in such a way that the 4 corners remain unscaled, but the four edges are scaled(or tiled) in one axis and the middle is scaled(or tiled) in both axis. So the graphical representation of this scenario will be something like this:
MaskedSprite is subclass of Sprite. It is using other sprite for masking own children.