前回の記事でシーンの内容は大体分かった。
ちょっと気になるのはvisibleSizeとoriginの値。
じゃあ、visibleSizeとoriginの値をラベルに表示させちゃおう。
    auto str = String();
    str.appendWithFormat("visible (%f %f)", visibleSize.width, visibleSize.height);
    auto label = Label::createWithTTF(str.getCString(), "fonts/msgothic.ttc", 24);
    if (label == nullptr)
    {
        problemLoading("'fonts/msgothic.ttc'");
    }
    else
    {
        // position the label on the center of the screen
        label->setPosition(Vec2(origin.x + visibleSize.width/2,
                                origin.y + visibleSize.height - label->getContentSize().height));
        // add the label as a child to this layer
        this->addChild(label, 1);
    }
    auto str2 = String();
    str2.appendWithFormat("origin (%f %f)", origin.x, origin.y);
    auto label2 = Label::createWithTTF(str2.getCString(), "fonts/msgothic.ttc", 24);
    if (label2 == nullptr)
    {
        problemLoading("'fonts/msgothic.ttc'");
    }
    else
    {
        // position the label on the center of the screen
        label2->setPosition(Vec2(origin.x + visibleSize.width/2,
                                origin.y + visibleSize.height - label->getContentSize().height * 2));
        // add the label as a child to this layer
        this->addChild(label2, 2);
    }
フォントについて
フォントはResource/fontsフォルダに拡張子ttfファイルが置いてあると思いますが、
Label::createWithTTF()をコールするときにフォントファイルを指定します。
Windowsだったらフォントはc:\windows\fontsがあるので、ここにあるttf/ttcファイルをここに置けば使用することができます。
文字列について
文字列はcocos2dx::Stringというクラスが存在するらしい。
これを使った方がいろいろと便利なので、これを使用する。
addChild()の第二パラメータ
これはzIndexとあったので、重ねて表示する場合、上に表示する順番を示すパラメータですね。
数字が大きい方が上に表示されるみたいです。
Windowsでの表示結果。
visibleは画面のサイズ、originは原点の座標のようです。
Windowsはこれでいいのですが、Android(pixel4a)の場合はこうなりました。
Pixel4aはちょっと横長なので、heightが少し小さいようです。
アスペクト比が異なり、アスペクト比は長辺が基準なので、その分heightが小さいのですね。
あと、左下にピンホールカメラがあるので、その分だけ、originのy座標が少し上になっていますね。
特殊ディスプレイ、嫌い。
まぁ、この点はどうするか後で考えよう。
		
		

