結局クラスは使えない、ということで、
やっぱりここは構造体にするしか無いだろう、と思いまして、
めっちゃ書き換えました。
詳細はgitHubを見てくれ。
https://github.com/takishita2nd/cocos2d-x_sample
typedef struct _ParameterLabel {
cocos2d::Label* label;
cocos2d::Vec2 point;
} ParameterLabel;
typedef struct _CharaWindow {
cocos2d::Sprite* sprite;
cocos2d::Vec2 point;
cocos2d::Size size;
ParameterLabel HPLabel;
ParameterLabel MPLabel;
} CharaWindow;
ウインドウは構造体でまとめました。
これをシーンクラスのprivateで保持し、画面を作成していきます。
auto chara = gameStatus.Charactors->begin();
for(int i = 0; i < 4; i++) {
window[i].sprite = cocos2d::Sprite::create("btn02_03_s_bl.png");
if (window[i].sprite != nullptr)
{
auto scaleRate = (visibleSize.height / 4) / window[i].sprite->getContentSize().height;
window[i].point = Vec2(xpos + origin.x,
origin.y + window[i].sprite->getContentSize().height * scaleRate * i);
window[i].size = Size(window[i].sprite->getContentSize().width * scaleRate,
window[i].sprite->getContentSize().height * scaleRate);
window[i].sprite->setAnchorPoint(Vec2(0,0));
window[i].sprite->setScale(scaleRate);
window[i].sprite->setPosition(window[i].point);
this->addChild(window[i].sprite);
window[i].HPLabel.label = Label::createWithTTF("", "fonts/msgothic.ttc", 10);
auto str = String();
str.appendWithFormat("HP:%d/%d", chara.operator*()->Hp, chara.operator*()->MaxHp);
window[i].HPLabel.label->setString(str.getCString());
window[i].HPLabel.label->setAnchorPoint(Vec2(0.0, 1.0));
window[i].HPLabel.point = Vec2(window[i].point.x + window[i].point.x / 10.0,
window[i].point.y + window[i].size.height - window[i].size.height / 20.0);
window[i].HPLabel.label->setPosition(window[i].HPLabel.point);
this->addChild(window[i].HPLabel.label, 10);
window[i].MPLabel.label = Label::createWithTTF("", "fonts/msgothic.ttc", 10);
str = String();
str.appendWithFormat("MP:%d/%d", chara.operator*()->Mp, chara.operator*()->MaxMp);
window[i].MPLabel.label->setString(str.getCString());
window[i].MPLabel.label->setAnchorPoint(Vec2(0.0, 1.0));
window[i].MPLabel.point = Vec2(window[i].point.x + window[i].point.x / 10.0,
window[i].HPLabel.label->getPosition().y - window[i].HPLabel.label->getContentSize().height - window[i].size.height / 20.0);
window[i].MPLabel.label->setPosition(window[i].MPLabel.point);
this->addChild(window[i].MPLabel.label, 10);
}
chara++;
}
もはや、何やってるか解らないレベル。
緻密にパーツを配置する座標とか計算しています。
で、左のウインドウをタップすると、中央に詳細画面が表示される仕組みにしています。
if(detailWindow.isShow)
{
this->removeChild(detailWindow.sprite);
this->removeChild(detailWindow.HPLabel.label);
this->removeChild(detailWindow.MPLabel.label);
}
for(int i = 0; i < 4; i++)
{
if(isTouch(touch->getLocation(), &window[i]))
{
detailWindow.isShow = true;
if(detailWindow.showIndex == i)
{
detailWindow.showIndex = -1;
break;
}
detailWindow.showIndex = i;
detailWindow.sprite = Sprite::create("btn02_03_s_bl.png");
detailWindow.sprite->setAnchorPoint(Vec2(0.0, 0.0));
detailWindow.sprite->setPosition(detailWindow.point);
detailWindow.size = Size(window[i].sprite->getContentSize().width * detailWindow.scaleRate,
window[i].sprite->getContentSize().height * detailWindow.scaleRate);
detailWindow.sprite->setScale(detailWindow.scaleRate);
this->addChild(detailWindow.sprite, 1);
auto character = gameStatus.Charactors->begin();
for(int j = 0; j < i; j++)
{
character++;
}
detailWindow.HPLabel.label = Label::createWithTTF("", "fonts/msgothic.ttc", 10);
auto str = String();
str.appendWithFormat("HP:%d/%d", character.operator*()->Hp, character.operator*()->MaxHp);
detailWindow.HPLabel.label->setString(str.getCString());
detailWindow.HPLabel.label->setAnchorPoint(Vec2(0.0, 0.0));
detailWindow.HPLabel.point = Vec2(detailWindow.point.x + detailWindow.point.x / 10.0,
detailWindow.point.y + detailWindow.size.height - detailWindow.size.height / 10.0);
detailWindow.HPLabel.label->setPosition(detailWindow.HPLabel.point);
this->addChild(detailWindow.HPLabel.label, 10);
detailWindow.MPLabel.label = Label::createWithTTF("", "fonts/msgothic.ttc", 10);
str = String();
str.appendWithFormat("MP:%d/%d", character.operator*()->Mp, character.operator*()->MaxMp);
detailWindow.MPLabel.label->setString(str.getCString());
detailWindow.MPLabel.label->setAnchorPoint(Vec2(0.0, 0.0));
detailWindow.MPLabel.point = Vec2(detailWindow.point.x + detailWindow.point.x / 10.0,
detailWindow.point.y + detailWindow.size.height - detailWindow.HPLabel.label->getContentSize().height - detailWindow.size.height / 10.0);
detailWindow.MPLabel.label->setPosition(detailWindow.MPLabel.point);
this->addChild(detailWindow.MPLabel.label, 10);
}
}
疲れた・・・