← Back

ofxSceneManager

github.com/kokinomura/ofxSceneManager · @kokinomura
OF 0.8 Releases Graphics

A lightweight addon for openFrameworks supporting crossfading, data passing and event handling. You can write your own scenes just like ofApp.

31 10 Last commit 12y ago Created 12y ago

Forks

Forks pushed to more recently than kokinomura/ofxSceneManager itself, plus any admin-confirmed fork with commits of its own — worth checking if you're hitting issues with the original.

WhatFor/ofxSceneManager by @WhatFor · ★ 0 · pushed 8y ago
kschaer/ofxSceneManager by @kschaer · ★ 1 · pushed 8y ago
dernster/ofxSceneManager by @dernster · ★ 0 · pushed 10y ago
schwittlick/ofxSceneManager by @schwittlick · ★ 0 · pushed 10y ago
loudcube/ofxSceneManager by @loudcube · ★ 0 · pushed 10y ago
0x705h/ofxSceneManager by @0x705h · ★ 0 · pushed 11y ago

Branches ahead of master

These branches have commits not yet on master — could be unmerged fixes or work in progress worth a look.

develop 3 commits ahead · last commit 12y ago

README

ofxSceneManager



A lightweight addon for openFrameworks supporting crossfading, data passing and event handling.

You can write your own scenes just like ofApp!

Dependency





Getting Started



#include "ofxScene.h"

class FirstScene : public ofxScene {
public:
    void setup();
    void update();
    void draw();
    void exit();
}


You have basic functions of ofApp and four additional functions you can override, and none of them are mandatory.

    void setup();
    void update();
    void draw();

    void willFadeIn();
    void willDraw();
    void willFadeOut();
    void willExit();

    void keyPressed(int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y);
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    void dragEvent(ofDragInfo dragInfo);
    void gotMessage(ofMessage msg);


class testApp : public ofBaseApp {
public:
    // definitions
    ofxSceneManager sceneManager;
}


void testApp::setup() {
    sceneManager.addScene(ofPtr<ofxScene>(new FirstScene));
    sceneManager.addScene(ofPtr<ofxScene>(new SecondScene));
}


void testApp::setup() {
    sceneManager.addScene(ofPtr<ofxScene>(new FirstScene));
    sceneManager.addScene(ofPtr<ofxScene>(new SecondScene));

    sceneManager.run();
}

void testApp::update() {
    sceneManager.update();
}

void testApp::draw() {
    sceneManager.draw();
}


Functionality



Transition

ofxSceneManager supports two types of transition.
void testApp::setup() {
    sceneManager.addScene(ofPtr<ofxScene>(new FirstScene));
    sceneManager.addScene(ofPtr<ofxScene>(new SecondScene));
    sceneManager.setExitByTime(false);  // You don't need this line since it's false by default.
    sceneManager.setSceneDuration(0.3, 0.3);  //fade-in, fade-out time.
}

void testApp::keyPressed(int key){
    if (key == ' ') {
        sceneManager.changeScene();
    }
}


void testApp::setup() {
    sceneManager.addScene(ofPtr<ofxScene>(new FirstScene));
    sceneManager.addScene(ofPtr<ofxScene>(new SecondScene));
    sceneManager.setExitByTime(true);
    sceneManager.setSceneDuration(0.3, 15.0, 0.3);  //fade-in, drawing, fade-out time respectively.
}


Call ofxSceneManager::changeScene() to change scenes.

Fading

ofxSceneManager does fading by default, and the background color while transition is a default color of oF. If you want another color or a picture as a background, you can change in testApp::draw();

void testApp::draw() {
	ofBackground(255, 255, 0);
	sceneManager.draw();
}


Data Passing

You have two kinds of setup(). ofxSceneManager calls one you implement.
    void setup()
    void setup(ofPtr<ofxScene> previousScene)


If a scene needs data of a previous scene, implement ``void setup(ofPtr<ofxScene> previousScene)` instead of `void setup()`. You can get data as public variables of the previous scene.

void SecondScene::setup() {

}


void SecondScene::setup(ofPtr<ofxScene> previousScene) {

}


Note: If you implement both, only
`setup()` will be called and `setup(ofPtr<ofxScene> previousScene)`` will be ignored.

Get this addon

HTTPS
SSH

Latest release

1.1 Version 1.1 published 12y ago
  • Add example-Advanced.
  • Add default event handlers such as mousePressed to ofxScene.