cocos study notes-Sprite

cocos study notes-Sprite

Reference: [jellythink](“http://www.jellythink.com/archives/742“)

1.Sprite class

Sprite is a 2D picture object,which can be defined by using a picture or part of picture.A Sprite can move, rotate, play action and so on. It consist of Texture,Frame,Animation.

important:

We usually use Texture2D to load the picture, then use it to produce SpriteFrame.After that , we add SpriteFrame to the Animation to produce action data.Finally, Animation produces Animate.Then Sprite puts it into action.

2.Sprite

API:

//create an empty sprite and then use `setTexture` to set the texture
static Sprite* create();
//create a sprite with an image
static Sprite* create(const std::string& filename);
//create a sprite with a Texture2D object
static Sprite* createWithTexture(Texture2D* texture);
//create a sprite by using spriteframe
static Sprite* createWithSpriteFrame(SpriteFrame *spriteFrame);
/*create a sprite by using a spriteframe,inside the programe, IDE will get `SpriteFrame` from `SpriteFrameCache` according to `SpriteFrameName` parameter */
static Sprite* createWithSpriteFrameName(const std::string& spriteFrameName)

3.SpriteBatchNode

If we need to render many sprites,we can use SpriteBatchNode to render them in one time to save spending,like this:

auto batchNode = SpriteBatchNode::create("CloseNormal.png", 1000);
batchNode->setPosition(Point::ZERO);
this->addChild(batchNode);
for (int i = 0;i < 1000;i++)
{
    int x = rand() % 960;
    int y = rand() % 640;
    auto testIcon = Sprite::createWithTexture(batchNode->getTexture());
    testIcon->setPosition(ccp(x, y));
    batchNode->addChild(testIcon);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值