---
title: "cocos2d 中scheduleUpdate和scheduleUpdateWithPriority对比"
author: "mmdev"
date: "2012-12-07T00:26:00Z"
tags: []
slug: "cocos2d-scheduleupdate-scheduleupdatewithpriority"
draft: false
lastmod: "2013-01-05T09:48:39Z"
id: 1761007
url: "https://mmdev.iteye.com/blog/1761007"
---

============================================================

博文原创，转载请声明出处

[蓝岩--移动互联网老兵](http://blog.csdn.net/shencaifeixia1)

============================================================

cocosd中CCLayer提供schedule方法来进行帧刷新，默认频率为1秒60帧，如下：

```
init {
  [self schedule:@selector(tick:)];
}
-(void) tick:(ccTime)dt
{
  // update your stuff here
}
```

同时cocos2d v0.99.还提供了以下两种更有效的方法来刷新帧。

```
[self scheduleUpdate];  // use priority == 0 ---A
[self scheduleUpdateWithPriority:an_integer]; ----B
```

然后在cclayer子类中实现update方法。

```
-(void) update:(ccTime)deltaTime
{
    // Update your stuff here
}
```

新老方法有什么不同呢？

1. 新方法提供了优先级可供选择，意味着你可以为n哥update方法排一下先后执行的顺序
2. 新方法可以节省一些内存，同时每次更新时候更加迅速