CCSprite精灵中的图片平铺作为游戏背景

代码:

   CCSize size = CCDirector::sharedDirector()->getWinSize();
    
   // The .png image MUST be power of 2 in order to create a continue effect.
   // eg: 32x64, 512x128, 256x1024, 64x64, etc..
   CCSprite *sprite = CCSprite::create("Images/pattern1.png", CCRectMake(0, 0, 4096, 4096));
   addChild(sprite, -1, kTagSprite1);
   sprite->setPosition(ccp(size.width/2,size.height/2));
   ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
   sprite->getTexture()->setTexParameters(&params);
作为平铺背景的图片要求:

长和宽的像素必须是2的n次方,比如:64x32、128x16等,可以根据实际需求进行设计

你可能感兴趣的:(图片平铺,CCSprite,cocos2d-x背景平铺)