Preface
recall Cocos2dx, before the Mac+xcode platform to learn cocos2dx, a year without contact cocos. have been doing unity3d. Today is still on the previous study temperature so warm, but no longer use Xcode to write. Use frequently used windows+vs2012 as a development environment to recall COCOS2DX. from the Ccsprite Elf class started to recall.
Ccsprite multiple ways to createThere are many ways to create a Ccsprite elf class, many constructors, which are listed in the centralized creation form. Contains a section to display and a cache frame, 2D map creation, and normal creation.
if (! Cclayer::init ()) {return false; } ccsize size = Ccdirector::shareddirector ()->getwinsize ()//Load Wizard//mode one ccsprite *sprite = Ccsprite::create (" Icon.png "); 123px*123px Picture Sprite->setposition (CCP (size.width*0.2,size.height*0.7)); This->addchild (sprite);//Mode two// Set the display area Ccsprite *sprite1 = ccsprite::create ("Icon.png", Ccrect (0,0,60,60)); Just take 60px*60px picture Sprite1->setposition (CCP (size.width*0.5,size.height*0.7)); This->addchild (sprite1);//Mode three Create 2d Arts to create sprites cctexture2d *texture = Cctexturecache::sharedtexturecache ()->addimage ("Icon.png"); Ccsprite *sprite2 = ccsprite::createwithtexture (texture); Sprite2->setposition (CCP (size.width*0.8,size.height* 0.7)); This->addchild (sprite2);//mode four//or set display area Ccsprite *sprite3 = Ccsprite::createwithtexture (Texture,ccrect ( 61.5,61.5,61.5,61.5)); Sprite3->setposition (CCP (size.width*0.2,size.height*0.3)); This->addchild (Sprite3); Mode five//cache frame Ccspriteframe *frame = ccspriteframe::create ("Icon.png", Ccrect (0, 0,61.5,61.5)); Ccsprite *sprite4 = Ccsprite::createwithspriteframe (frame); Sprite4->setposition (CCP (size.width*0.5,size.height *0.3)); This->addchild (sprite4);//Mode six/*ccspriteframecache::sharedspriteframecache () Addspriteframeswithfile ("Img.plist"); Ccsprite *sprite5 = Ccsprite::createwithspriteframename ("Icon.png"); Sprite5->setposition (CCP (size.width*0.7, size.height*0.3)); This->addchild (SPRITE5); * *
ccsprite zoom in and zoom outCcsprite->setscale (): The number of participants in the 0~ infinity, you can achieve the sprite zoom and zoom function.
The Elves zoom in and out Ccsprite *sprites= ccsprite::create ("Icon.png"); Picture of 123px*123px Sprites->setposition (CCP (size.width*0.2,size.height*0.5)); Sprites->setscale (0.5f); this- >addchild (SpriteS); Ccsprite *spritem = ccsprite::create ("Icon.png"); Picture of 123px*123px Spritem->setposition (CCP (size.width*0.7,size.height*0.5)); Spritem->setscale (1.5f); this- >addchild (Spritem);
Setscalex,setscaley is only for X-, Y-direction scalingFor example: Sprite->setscalex (1.5f); Sprite2->setscaley (1.5f);
Ccsprite Rotationccsprite->setrotation (); The number of parameters is the degree, the positive number represents the clockwise rotation of how many degrees, the negative number represents the degree of counterclockwise rotation.
The sprite spins ccsprite *spritel= ccsprite::create ("Icon.png"); Picture of 123px*123px Spritel->setposition (CCP (size.width*0.3,size.height*0.5)); Spritel->setrotation (30.0f); This->addchild (Spritel); Ccsprite *spriter= ccsprite::create ("Icon.png"); Picture of 123px*123px Spriter->setposition (CCP (size.width*0.8,size.height*0.5)); Spriter->setrotation ( -30.0f); This->addchild (Spriter);
ccsprite TiltCcsprite->setskewy (); The number of parameters is the degree, and the positive number indicates how many degrees are tilted clockwise. Negative numbers indicate how many degrees are tilted counterclockwise.
Elf Tilt ccsprite *spritel= ccsprite::create ("Icon.png"); Picture of 123px*123px Spritel->setposition (CCP (size.width*0.3,size.height*0.5)); Spritel->setskewy (30.0f); this- >addchild (Spritel); Ccsprite *spriter= ccsprite::create ("Icon.png"); Picture of 123px*123px Spriter->setposition (CCP (size.width*0.8,size.height*0.5)); Spriter->setskewy ( -30.0f); This->addchild (Spriter);
ccsprite setting is not visible and discolored
Sprites visible and discolored//set invisible Ccsprite *spritel= ccsprite::create ("Icon.png"); 123px*123px Picture Spritel->setposition (CCP (size.width*0.3,size.height*0.5)); spritel->setvisible (false); This->addchild (Spritel);//become Red Ccsprite *spriter= ccsprite::create ("Icon.png"); Picture of 123px*123px Spriter->setposition (CCP (size.width*0.8,size.height*0.5)); Spriter->setcolor (CCC3 (255,0,0 )); This->addchild (Spriter);
ccsprite Setting Transparency
Set the transparency ccsprite *spritel= ccsprite::create ("Icon.png"); Picture of 123px*123px Spritel->setposition (CCP (size.width*0.3,size.height*0.5)); spritel->setopacity (100);//0~ 255this->addchild (Spritel); Ccsprite *spriter= ccsprite::create ("Icon.png"); Picture of 123px*123px Spriter->setposition (CCP (size.width*0.7,size.height*0.5)); spriter->setopacity (230);//0~ 255this->addchild (Spriter);
Ccsprite replacing Pictures
Replace picture Ccsprite *spriter= ccsprite::create ("Icon.png"); Picture of 123px*123px Spriter->setposition (CCP (size.width*0.7,size.height*0.5)); spriter->setopacity (230);//0~ 255this->addchild (Spriter); Spriter->settexture (Cctexturecache::sharedtexturecache ()->addImage (" Closenormal.png "));
Welcome to watch my scarf.
==================== csdn Blog Column =================
myblog:http://blog.csdn.net/dingxiaowei2013 myqq:1213250243
Unity QQ Group:375151422 cocos2dx QQ Group: 280818155
====================== learn from each other and progress together ===================
[WINDOWS+COCOS2DX] Ccsprite Elf Class