1、精灵创建的3种方式
</pre><p><pre name="code" >#include "T02LayerSprite.h"CCScene * T02LayerSprite::scene(){ CCScene * scene = CCScene::create(); T02LayerSprite * layer = T02LayerSprite::create(); scene->addChild(layer); return scene;}bool T02LayerSprite::init(){ if (!cclayer::init()) { return false; } //系统默认的图片路径是工程下Resource, //截图功能:至左上角开始截图,向右下,,CCRectMake(0,480,320) CCSprite * backGround = CCSprite::create("sprite/background.jpg",CCRectMake(0,320)); backGround->setAnchorPoint(ccp(0,0)); //backGround->setScaleX(0.8); backGround->setposition(ccp(0,0)); addChild(backGround); CCImage * image = new CCImage; image->initWithImagefile("sprite/plant.png"); image->autorelease(); //纹理,本质就是图片,OpenGL术语,加载进内存 CCTexture2D * texture = new CCTexture2D; texture->initWithImage(image); texture->autorelease(); CCSprite * plant = CCSprite::createWithTexture(texture); plant->setposition(ccp(100,160)); addChild(plant); CCTexture2D * texture2 = CCTextureCache::sharedTextureCache()->addImage("sprite/bullet.png"); CCSprite *bullet = CCSprite::createWithTexture(texture2); bullet->setposition(ccp(250,180)); addChild(bullet); //本质是,截帧动画当中的一帧,一帧的本质其实就是一张图片,来创建精灵 CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithfile("sprite/framecache/zombIE.pList"); CCSpriteFrame * sprFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByname("z_1_attack_05.png"); CCSprite * zombIE = CCSprite::createWithSpriteFrame(sprFrame); zombIE->setposition(ccp(420,180)); addChild(zombIE); CCMoveBy * by = CCMoveBy::create(3,ccp(300,0)); bullet->runAction(by); return true;}
#ifndef __T02LayerSprite_H__#define __T02LayerSprite_H__#include "cocos2d.h"USING_NS_CC;class T02LayerSprite : public cclayer{public: static CCScene * scene(); CREATE_FUNC(T02LayerSprite); bool init();};#endif
总结
以上是内存溢出为你收集整理的Cocos2d-X----精灵全部内容,希望文章能够帮你解决Cocos2d-X----精灵所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)