基础知识

来源:互联网 发布:安讯士网络摄像机 编辑:程序博客网 时间:2024/05/17 07:20
1.获取随机数方法(通过宏来获取):
1.int random = CCRANDOM_0_1(); 产生0~1之间的随机数

2.int random =CCRANDOM_0_1()*100; 产生0~100之间的随机数

2.cocos2d-x 绘制图片不再draw里进行实现,而是使用如下的方法(这里和j2me,android里有区别):                CCSprite* pSprite = CCSprite::create("bg.png");

     CC_BREAK_IF(! pSprite);


     // Place the sprite on the center of the screen

     pSprite->setPosition(ccp(size.width/2, size.height/2));


     // Add the sprite to HelloWorld layer as a child layer.

     this->addChild(pSprite, 0);

3.文本绘制和上边一样也不再draw里直接实现,有一个标签直接使用就可以如下:

   CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);

     CC_BREAK_IF(! pLabel);


     // Get window size and place the label upper.

     CCSize size = CCDirector::sharedDirector()->getWinSize();

     pLabel->setPosition(ccp(size.width / 2, size.height - 50));


     // Add the label to HelloWorld layer as a child layer.

     this->addChild(pLabel, 1);

原创粉丝点击