Giter Site home page Giter Site logo

ragnaringi / ofxscenemanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kokinomura/ofxscenemanager

0.0 2.0 0.0 350 KB

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

License: MIT License

Makefile 3.51% C++ 90.62% Objective-C++ 5.87%

ofxscenemanager's Introduction

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

  • Write your own subclasses of ofxScene.
#include "ofxScene.h"

class FirstScene : public ofxScene {
public:
    void setup();
    void update();
    void draw();
    void exit();
}
  • Fill all functions you need.

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);
  • Instantiate ofxSceneManager and add scenes.
class testApp : public ofBaseApp {
public:
    // definitions
    ofxSceneManager sceneManager;
}
void testApp::setup() {
    sceneManager.addScene(ofPtr<ofxScene>(new FirstScene));
    sceneManager.addScene(ofPtr<ofxScene>(new SecondScene));
}
  • Run the ofxSceneManager.
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.

  • Transition when you trigger. (default)
  • Transition after certain period of time.
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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.