代码如下:
//set background scene bgmap = Sprite::create(PASTE.PNG); bgmap->setPosition(VisibleRect::center());//这句自己根据需要修改 Size mywinsize=Director::getInstance()->getWinSize(); float winw = mywinsize.width; //获取屏幕宽度 float winh = mywinsize.height;//获取屏幕高度 float spx = bgmap->getTextureRect().getMaxX(); float spy = bgmap->getTextureRect().getMaxY(); bgmap->setScaleX(winw/spx); //设置精灵宽度缩放比例 bgmap->setScaleY(winh/spy); this->addChild(bgmap);原文链接:https://www.f2er.com/cocos2dx/341626.html