前提・実現したいこと
現在cocos2dにてWindowsで開発を行っていました。
今後スマートフォンに移植したいため、Androidの移植作業を行っていました。
メニュー画面は表示できるようにしたのですが、ドット絵のキャラクターが半透明の状態で表示されます。
すみませんがどなたかこの現象を解消する方法をご存じないでしょうか?
該当のソースコード
//画像ロード画面一部抜粋 void BasicPlayer::loadResources() { //ファイルパス std::string filePath[] = { "$Fighter_1.png", "$Fighter_2.png", "$Fighter_3.png", "$Fighter_4.png", "$Fighter_10.png", "$Fighter_11.png", "$Fighter_20.png", "$Fighter_40.png" }; //戻り画像フラグ bool returnImageFlag[][4]{ {true,false,false,false}, {true,false,true,true}, {true,true,false,false}, {true,false,false,true}, {false,false,true,true}, {false,false,false,false}, {true,true,false,true}, {true,false,false,false} }; //アニメーションスピード float animationSpeed[][4]{ {0.2,0.1,0.1,0.1}, {0.1,0.15,0.1,0.2}, {0.1,0.1,0.1,0.1}, {0.2,0.1,0.1,0.2}, {0.1,0.1,0.1,0.1}, {0.1,0.1,0.1,0.1}, {0.2,0.2,0.1,0.2}, {0.2,0.2,0.1,0.2} }; int count = 0; for (int i = 0; i < 8; i++) { // 文字列カウント // 対象の画像の読み取り(読み捨て用) // auto baseSprite = cocos2d::Sprite::create("RPG/Fighter/" + filePath[i]); auto baseSprite = cocos2d::Sprite::createWithSpriteFrameName(filePath[i]); // Spriteからテクスチャーの取得(読み捨て用) auto textureSource = baseSprite->getTexture(); textureSource->setAliasTexParameters(); textureSource->setAntiAliasTexParameters(); //baseSprite->retain(); //textureSource->retain(); // 今回はドット絵なのでアンチエイリアスをOFF //textureSource->setAliasTexParameters(); //textureSource->setAliasTexParameters(); // 1コマの大きさを取得しておく frameWidth = baseSprite->getContentSize().width / 4; frameHeight = baseSprite->getContentSize().height / 4; this->setContentSize(cocos2d::Size(frameWidth, frameHeight)); // 画像の半分の大きさを取っておく int harfWidth = baseSprite->getContentSize().width / 2; for (int y = 0; y < 4; y++) { // アニメーションを格納するオブジェクトの作成 cocos2d::Animation *animation = cocos2d::Animation::create(); animation->setDelayPerUnit(animationSpeed[i][y]); animation->setRestoreOriginalFrame(false); for (int x : { 0, 1, 2, 3 }) { // アニメーション4枚のテクスチャを考慮する int _x = frameWidth * x; int _y = y * frameHeight; CCLOG("(%d, %d)", _x, _y); // テクスチャーから画像を切り出し animation->addSpriteFrameWithTexture(textureSource, cocos2d::Rect(_x, _y, frameWidth, frameHeight)); } if (returnImageFlag[i][y]) { for (int x : { 2, 1, 0 }) { // 折り返しアニメーションを考慮する。 int _x = frameWidth * x; int _y = y * frameHeight; CCLOG("(%d, %d)", _x, _y); // テクスチャーから画像を切り出し animation->addSpriteFrameWithTexture(textureSource, cocos2d::Rect(_x, _y, frameWidth, frameHeight)); } } cocos2d::Animate *anime = cocos2d::Animate::create(animation); //anime->retain(); this->animatonTable.insert((PlayerDirection)(y + (4 * i) + count), anime); if(i==1 && y==1){ // アニメーションを格納するオブジェクトの作成 auto *animation = cocos2d::Animation::create(); animation->setDelayPerUnit(animationSpeed[i][y]); animation->setRestoreOriginalFrame(false); for (int x : { 3, 2, 1, 0 }) { // アニメーション4枚のテクスチャを考慮する int _x = frameWidth * x; int _y = y * frameHeight; CCLOG("(%d, %d)", _x, _y); // テクスチャーから画像を切り出し animation->addSpriteFrameWithTexture(textureSource, cocos2d::Rect(_x, _y, frameWidth, frameHeight)); } count++; cocos2d::Animate *anime = cocos2d::Animate::create(animation); //anime->retain(); this->animatonTable.insert((PlayerDirection)(y + (4 * i)+ count), anime); } } } // 攻撃判定 auto BoundBoxAttack = cocos2d::Sprite::create(); BoundBoxAttack->setTextureRect(cocos2d::Rect(0, 0, 30, 48)); // BoundBoxAttack->setTextureRect(cocos2d::Rect(20, 24, 30, 48)); BoundBoxAttack->setColor(cocos2d::Color3B(255, 0, 0)); BoundBoxAttack->setOpacity(0); BoundBoxAttack->setPosition(20, 24); // BoundBoxAttack->setPosition(0, 0); BoundBoxAttack->setTag(1); this->addChild(BoundBoxAttack); // プレイヤー当たり判定 auto BoundBoxSelf = cocos2d::Sprite::create(); BoundBoxSelf->setTextureRect(cocos2d::Rect(0, 0, 30, 48)); // BoundBoxSelf->setTextureRect(cocos2d::Rect(47, 24, 30, 48)); BoundBoxSelf->setColor(cocos2d::Color3B(0, 255, 255)); BoundBoxSelf->setOpacity(0); BoundBoxSelf->setPosition(47, 24); // BoundBoxSelf->setPosition(0, 0); BoundBoxSelf->setTag(2); auto box = BoundBoxSelf->getBoundingBox(); this->addChild(BoundBoxSelf); //this->setOpacity(0); //アップデート実行 //this->scheduleUpdate(); }
試したこと
setOpacity(255);
setColor(cocos2d::Color3B(255,255,255));
の状態にしても画像が半透明の状態で表示されます。
参考画像
補足情報(FW/ツールのバージョンなど)
cocos2d-x 4.0
Android 9.0
あなたの回答
tips
プレビュー