1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include "cocos2d.h"
USING_NS_CC;
class
GameScene :
public
cocos2d::Layer
{
public
:
static
cocos2d::Scene* createScene();
virtual
bool
init();
void
menuCallback(Ref* pSender);
CREATE_FUNC(GameScene);
private
:
//注意不能用auto关键字
Size size;
Sprite *sprite;
};
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Created by Jacedy on 14-8-11.
#include "GameScene.h"
#include <stdlib.h>
USING_NS_CC;
cocos2d::Scene* GameScene::createScene()
{
auto
scene = Scene::create();
//创建一个场景
auto
layer = GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
bool
GameScene::init()
{
if
(!Layer::init())
//初始化父类
return
false
;
//获取屏幕大小
size = Director::getInstance()->getVisibleSize();
//auto size = Director::getInstance()->getWinSize();
//获取系统时间
struct
timeval now;
gettimeofday(&now, NULL);
//初始化随机种子
//timeval是个结构体,里边有俩个变量,一个是以秒为单位的,一个是以微妙为单位的
unsigned rand_seed = (unsigned)(now.tv_sec*1000 + now.tv_usec/1000);
//都转化为毫秒
srand
(rand_seed);
for
(
int
i=0; i<100; i++) {
int
_rand =
rand
()%100;
//产生0~99的随机数
//int _rand2 = random()%100;
log
(
"%d"
, _rand);
}
return
true
;
}
void
GameScene::menuCallback(Ref* pSender)
{
}
|