cocos2d-x 笔记(三) sprite类

Orca原创,转贴请标明链接Orca的移动开发轨迹

目前整个学习笔记的版本是cocos2d-x 2.1.0beta3。

一、sprite的创建

1.基本的创建方法

先打开HelloWorldScene.cpp,重写一遍背景的加入。

		// 进行测试,首先是加入普通sprite
		// 计算整个屏幕的size
		CCDirector * _pdirector = CCDirector::sharedDirector();
		CCSize winSize = _pdirector->getVisibleSize();
		CCSprite *bg = CCSprite::create("helloworld.png");
		bg->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(bg);

这是最基本的加入sprite的方式。先用文件生成指向sprite对象的指针,然后设置这个对象的属性。设置完了以后再加入当前的layer。

sprite即精灵,这是我们整个游戏当中的基础对象。

对于sprite的属性,我们可以查阅官方文档。

可见它继承于Node,TextureProtocol,RGBAProtocol

可以先在sprite.h里面看一下sprite类的声明。

先看有关创建部分

   /** Creates an sprite with an image filename.
     The rect used will be the size of the image.
     The offset will be (0,0).
     */
    static CCSprite* create(const char *pszFileName);

    /** Creates an sprite with an image filename and a rect.
     The offset will be (0,0).
     */
    static CCSprite* create(const char *pszFileName, const CCRect& rect);

其实我们可以发现,以前有许多创建sprite的接口,但是都已经被标注为This interface will be deprecated sooner or later.

也就是说,现在官方推荐使用的创建sprite的方式就只剩下两个重载函数。

1.static CCSprite* create(

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值