void ThirdGuanScene::initMap()
{
int x = 1;
int y = 0;
for (int i = 1; i < xCount - 1; i++) {
for (int j = 1; j < yCount - 1; j++) {
mMap[i][j] = x;
if (y == 1) {
x++;
y = 0;
/* if (x == iconCount) {
x = 1;
}*/
}
else {
y = 1;
}
}
}
drawMap();
}
void ThirdGuanScene::drawMap()
{
log("==================================");
for (int x = 0; x < xCount; x++) {
for (int y = 0; y < yCount; y++) {
if (mMap[x][y] > 0) {
char iconName[36] = { 0 };
sprintf(iconName, "1-%d.png", mMap[x][y]);
log("%s ,", iconName);
log("%d ,", mMap[x][y]);
auto position = indextoScreen(x, y);
icon = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(iconName));
icon->setPosition(position);
int tag = (yCount - 2) * (x - 1) + y;
log("tag = %d", tag);
addChild(icon, 100, tag);
}
}
}
}
uj5u.com熱心網友回復:
你的iconName值每次都一樣嗎uj5u.com熱心網友回復:
iconname是固定的36個圖片。按數字大小排列下來的。uj5u.com熱心網友回復:
iconname是固定的36個圖片。按數字大小排列下來的。
uj5u.com熱心網友回復:
hello你好啊666uj5u.com熱心網友回復:
代碼邏輯錯了吧,cocos2dx圖片一般會合成大圖用plist加載,效率會好。uj5u.com熱心網友回復:
你的sprintf(iconName, "1-%d.png", mMap[x][y]); 中顯示的是你的圖片是1,2, 3,30命名的嗎,不是01,02,03,30命名的是吧,如果是兩位就需要占位符轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/53368.html
標籤:Cocos2d-x
