###前提・実現したいこと
ここに質問したいことを詳細に書いてください
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
cocos2d-x 複数のTableViewを使用する時、複数のTableViewのCellが一つしかありません。
各のTableViewに別の情報を表示したいと思います
例えばTableView1にはゲームのスキル情報を、TableView2にはアイテムの情報を表示したいんです。
この場合はどうすれば解決できますか?
Please Help me..!
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
ここにご自身が実行したソースコードを書いてください
// make TableView
// skill TableView
tableView1 = TableView::create(this, Size(550, 330));
tableView1->setDirection(ScrollView::Direction::VERTICAL);
tableView1->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
tableView1->setDelegate(this);
tableView1->setTag(100);
tableView1->setPosition(Vec2(mainCharWindowTable->getContentSize().width / 2, mainCharWindowTable->getContentSize().height / 1.85));
mainCharWindowTable->addChild(tableView1, 3);
tableView1->reloadData();
// item TableView tableView2 = TableView::create(this, Size(550, 300)); tableView2->setDirection(ScrollView::Direction::VERTICAL); tableView2->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN); tableView2->setDelegate(this); tableView2->setTag(200); tableView2->setPosition(Vec2(mainCharWindowTable->getContentSize().width / 2, mainCharWindowTable->getContentSize().height / 13)); mainCharWindowTable->addChild(tableView2, 3); tableView2->reloadData();
// make Cell
TableViewCell* MainCharWindow::tableCellAtIndex(TableView* table, ssize_t size)
{
String* itemPathString = String::createWithFormat("Images/item_icons/slot.png");
auto itemNameString = String::createWithFormat("아이템%d", size + 1);
// 古いセルをひとつ取り除いて TableViewCell *cell = table->dequeueCell(); if (!cell) { // 取り出せなかった場合、新しいセルを作る cell = new TableViewCell(); cell->autorelease(); // セルの背景 auto bg = Sprite::create(); bg->setAnchorPoint(Vec2(0, 0)); bg->setTextureRect(Rect(0, 0, 660, 84)); bg->setColor(Color3B(255, 187, 0)); cell->addChild(bg); auto bgSprite = Sprite::create("Images/item_icons/slot.png"); bgSprite->setScale(0.7f); bgSprite->setAnchorPoint(Vec2::ZERO); bgSprite->setTag(789); auto itemNameLabel = Label::createWithSystemFont(itemNameString->getCString(), "Arial", 34); //attackLabel->setAnchorPoint(Vec2(0, 0)); itemNameLabel->setPosition(Vec2(150, 65)); itemNameLabel->setColor(Color3B::BLACK); itemNameLabel->setTag(2); cell->addChild(itemNameLabel, 100); auto itemCountLabel = Label::createWithSystemFont("수량 : ", "Arial", 34); //attackLabel->setAnchorPoint(Vec2(0, 0)); itemCountLabel->setPosition(Vec2(150, 25)); itemCountLabel->setColor(Color3B::BLACK); itemCountLabel->setTag(2); cell->addChild(itemCountLabel, 100); //if (idx < 5) //{ //auto itemPathString = String::createWithFormat("Images/item_icons/item0%d.png", idx + 1); //iconSprite = Sprite::create(itemPathString->getCString()); //iconSprite->setScale(0.7f); //iconSprite->setAnchorPoint(Vec2(0, 0)); //iconSprite->setTag(123); //cell->addChild(iconSprite); //} } else { //创建了就不需要再重新创建了,不然你会发现图片跟文字都不对 //auto attackLabel = dynamic_cast<Label*>(cell->getChildByTag(2)); //attackLabel->setString(string->getCString()); auto aTexture = TextureCache::sharedTextureCache()->addImage(itemPathString->getCString()); //auto pSprite = (Sprite*)cell->getChildByTag(123); //pSprite->setTexture(aTexture); } // アイテム名 //auto name = _itemList[idx].name; //auto nameLabel = Label::createWithSystemFont(name.c_str(), "Arial", 48); //auto nameLabel = Label::createWithSystemFont("item01", "Arial", 48); //nameLabel->setAnchorPoint(Vec2(0, 0.5)); //nameLabel->setPosition(Vec2(50, visibleSize.height * 0.15)); //nameLabel->setColor(Color3B::BLACK); //cell->addChild(nameLabel); // 攻撃力 //auto attack = StringUtils::format("こうげき力:%d", _itemList[idx].attack); //auto attackLabel = Label::createWithSystemFont(attack.c_str(), "Arial", 36); return cell;
}
###試したこと
課題に対してアプローチしたことを記載してください
TableViewCell* MainCharWindow::tableCellAtIndex(TableView* table, ssize_t size)メソッドを二つ作ってみましたがダメでした
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
あなたの回答
tips
プレビュー