zoukankan      html  css  js  c++  java
  • cocos2dx自定义事件类封装

    GameEvent.h:

     1 #pragma once
     2 #include "cocos2d.h"
     3 USING_NS_CC;
     4 
     5 class GameEvent {
     6 public:
     7     //封装派发数据
     8     static void dispatchSet(std::string eventName, void *optionalUserData = nullptr);
     9     static void dispatch(std::string eventName, void *optionalUserData = nullptr);
    10     static void addEventListener(std::string eventName, const std::function<void(EventCustom*)>& callback);
    11     static void removeEventListener(std::string eventName);
    12 };

    GameEvent.cpp:

     1 #include "GameEvent.h"
     2 
     3 
     4 
     5 void GameEvent::dispatch(std::string eventName, void *optionalUserData) {
     6     Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(eventName, optionalUserData);
     7 }
     8 
     9 void GameEvent::addEventListener(std::string eventName, const std::function<void(EventCustom*)>& callback) {
    10     Director::getInstance()->getEventDispatcher()->addCustomEventListener(eventName, callback);
    11 }
    12 
    13 void GameEvent::removeEventListener(std::string eventName) {
    14     Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(eventName);
    15 }
  • 相关阅读:
    K8S-安全机制
    K8S-Service
    K8S-Pod资源管理
    K8S-kubelet启动过程
    每日进度
    每日进度
    每日进度
    每日进度
    每日进度
    归纳及计划
  • 原文地址:https://www.cnblogs.com/xyida/p/4325067.html
Copyright © 2011-2022 走看看