Merge pull request #14238 from pandamicro/v3

Add cc.Director.EVENT_BEFORE_UPDATE
This commit is contained in:
pandamicro 2015-10-28 15:50:37 +08:00
commit 7d832b0753
3 changed files with 11 additions and 2 deletions

View File

@ -89,6 +89,7 @@ extern const char* cocos2dVersion(void);
const char *Director::EVENT_PROJECTION_CHANGED = "director_projection_changed";
const char *Director::EVENT_AFTER_DRAW = "director_after_draw";
const char *Director::EVENT_AFTER_VISIT = "director_after_visit";
const char *Director::EVENT_BEFORE_UPDATE = "director_before_update";
const char *Director::EVENT_AFTER_UPDATE = "director_after_update";
Director* Director::getInstance()
@ -157,6 +158,8 @@ bool Director::init(void)
_eventAfterDraw->setUserData(this);
_eventAfterVisit = new (std::nothrow) EventCustom(EVENT_AFTER_VISIT);
_eventAfterVisit->setUserData(this);
_eventBeforeUpdate = new (std::nothrow) EventCustom(EVENT_BEFORE_UPDATE);
_eventBeforeUpdate->setUserData(this);
_eventAfterUpdate = new (std::nothrow) EventCustom(EVENT_AFTER_UPDATE);
_eventAfterUpdate->setUserData(this);
_eventProjectionChanged = new (std::nothrow) EventCustom(EVENT_PROJECTION_CHANGED);
@ -185,6 +188,7 @@ Director::~Director(void)
CC_SAFE_RELEASE(_actionManager);
CC_SAFE_DELETE(_defaultFBO);
delete _eventBeforeUpdate;
delete _eventAfterUpdate;
delete _eventAfterDraw;
delete _eventAfterVisit;
@ -265,6 +269,7 @@ void Director::drawScene()
//tick before glClear: issue #533
if (! _paused)
{
_eventDispatcher->dispatchEvent(_eventBeforeUpdate);
_scheduler->update(_deltaTime);
_eventDispatcher->dispatchEvent(_eventAfterUpdate);
}

View File

@ -97,7 +97,9 @@ class CC_DLL Director : public Ref
{
public:
/** Director will trigger an event when projection type is changed. */
static const char *EVENT_PROJECTION_CHANGED;
static const char* EVENT_PROJECTION_CHANGED;
/** Director will trigger an event before Schedule::update() is invoked. */
static const char* EVENT_BEFORE_UPDATE;
/** Director will trigger an event after Schedule::update() is invoked. */
static const char* EVENT_AFTER_UPDATE;
/** Director will trigger an event after Scene::render() is invoked. */
@ -538,7 +540,7 @@ protected:
@since v3.0
*/
EventDispatcher* _eventDispatcher;
EventCustom *_eventProjectionChanged, *_eventAfterDraw, *_eventAfterVisit, *_eventAfterUpdate;
EventCustom *_eventProjectionChanged, *_eventAfterDraw, *_eventAfterVisit, *_eventBeforeUpdate, *_eventAfterUpdate;
/* delta time since last tick to main loop */
float _deltaTime;

View File

@ -1591,7 +1591,9 @@ cc.Touch.prototype.getLocationY = function(){
cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed";
cc.Director.EVENT_AFTER_DRAW = "director_after_draw";
cc.Director.EVENT_AFTER_VISIT = "director_after_visit";
cc.Director.EVENT_BEFORE_UPDATE = "director_before_update";
cc.Director.EVENT_AFTER_UPDATE = "director_after_update";
cc.Director.EVENT_BEFORE_SCENE_LAUNCH = "director_before_scene_launch";
cc.Director.prototype.runScene = function(scene){
if (!this.getRunningScene()) {