Cocos2D-x schedule&scheduleUpdate 사용

Cocos2D-x 학습 시작
cocos2d-x 에서 여러 개의 타이머 방법 을 제공 하여 CCNode.h 라 는 헤더 파일 에서 해당 하 는 방법 을 찾 을 수 있 습 니 다.다음은 정리 하 겠 습 니 다.
(1)아래 의 이 방법 을 사용 하면 노드 는 프레임 마다 update 방법 을 실행 합 니 다.
/** 
     * Schedules the "update" method. 
     *
     * It will use the order number 0. This method will be called every frame.
     * Scheduled methods with a lower order value will be called before the ones that have a higher order value.
     * Only one "update" method could be scheduled per node.
     */
    void scheduleUpdate(void);

주석 에서 이 방법의 order(우선 급수)는 0 이 고 order(우선 급수)는 작 을 수록 먼저 배 치 됩 니 다.모든 노드 에 update 스케줄 링 방법 만 있 을 수 있 습 니 다.
이 update 방법 을 다시 쓰 는 것 을 주의 하 세 요.
/* 
     * Update method will be called automatically every frame if "scheduleUpdate" is called, and the node is "live"
     */
    virtual void update(float delta);

이 타이머 호출 을 취소 하 는 것 도 간단 하 다.
/* 
     * Unschedules the "update" method.
     * @see scheduleUpdate();
     */
    void unscheduleUpdate(void);

cocos2d-x 에 서 는 이러한 방법 도 제공 합 니 다.이 방법 은 scheduleUpdate 와 유사 합 니 다.다만 하나의 우선 순위 가 지정 되 어 있 을 뿐 우선 순위 가 작 을 수록 먼저 실 행 됩 니 다.
/** 
     * Schedules the "update" method with a custom priority. 
     *
     * This selector will be called every frame.
     * Scheduled methods with a lower priority will be called before the ones that have a higher value.
     * Only one "update" selector could be scheduled per node (You can't have 2 'update' selectors).
     */
    void scheduleUpdateWithPriority(int priority);

(2)cocos2d-x 에 서 는 여러 가지 schedule 방법 도 제공 했다.이 방법 들 의 호출 은 노드 를 지정 하여 특정한 selector 를 실행 할 수 있 습 니 다.
/**
     * Schedules a custom selector.
     *
     * If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.
     * @code
     * // firstly, implement a schedule function
     * void MyNode::TickMe(float dt);
     * // wrap this function into a selector via schedule_selector marco.
     * this->schedule(schedule_selector(MyNode::TickMe), 0, 0, 0);
     * @endcode
     *
     * @param interval  Tick interval in seconds. 0 means tick every frame. If interval = 0, it's recommended to use scheduleUpdate() instead.
     * @param repeat    The selector will be excuted (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.
     * @param delay     The amount of time that the first tick will wait before execution.
     */
    void schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay);

매개 변수 에 selector,실행 시간 간격,반복 실행 횟수(kCCRepeatForever 를 사용 하여 무한 순환 을 표시 할 수 있 음)를 지정 하여 실행 전 지연 시간 을 시작 합 니 다.
/**
     * Schedules a custom selector with an interval time in seconds.
     * @see schedule(SEL_SCHEDULE, float, unsigned int, float)
     *
     * @param selector      A function wrapped as a selector
     * @param interval      Callback interval time in seconds. 0 means tick every frame,
     */
    void schedule(SEL_SCHEDULE selector, float interval);

매개 변수 에 selector 와 실행 시간 간격 을 지정 하 였 습 니 다.
/**
     * Schedules a selector that runs only once, with a delay of 0 or larger
     * @see schedule(SEL_SCHEDULE, float, unsigned int, float)
     *
     * @param selector      A function wrapped as a selector
     * @param delay         The amount of time that the first tick will wait before execution.
     */
    void scheduleOnce(SEL_SCHEDULE selector, float delay);

매개 변수 에 selector 와 실행 전 지연 시간 이 지정 되 어 있 습 니 다.
 /**
     * Schedules a custom selector, the scheduled selector will be ticked every frame
     * @see schedule(SEL_SCHEDULE, float, unsigned int, float)
     *
     * @param selector      A function wrapped as a selector
     */
    void schedule(SEL_SCHEDULE selector);

이 방법 에서 매개 변 수 는 selector 만 지정 하면 그 역할 은 scheduleUpdate 와 같 습 니 다.즉,노드 는 모든 프레임 에서 selector 방법 을 실행 합 니 다.
⑤ 타이머 schedule 을 취소 하 는 방법
/** 
     * Unschedules a custom selector.
     * @see schedule(SEL_SCHEDULE, float, unsigned int, float)
     *
     * @param selector      A function wrapped as a selector
     */
    void unschedule(SEL_SCHEDULE selector);

모든 타이머 방법 을 취소 합 니 다.
/** 
     * Unschedule all scheduled selectors: custom selectors, and the 'update' selector.
     * Actions are not affected by this method.
     */
    void unscheduleAllSelectors(void);

⑥ 다음 두 가지 방법 은 타이머 복원 과 일시 정지 에 사용 된다.그들 은 일반적으로 onEnter 와 onExit 방법 으로 호출 된다.
/** 
     * Resumes all scheduled selectors and actions.
     * This method is called internally by onEnter
     */
    void resumeSchedulerAndActions(void);
    /** 
     * Pauses all scheduled selectors and actions.
     * This method is called internally by onExit
     */
    void pauseSchedulerAndActions(void);

좋은 웹페이지 즐겨찾기