fairygui / FairyGUI-cocos2dx

A flexible UI framework for Cocos2d-x
https://www.fairygui.com
MIT License
473 stars 109 forks source link

How to make FairyGUI keep editor size? #110

Closed paulocoutinhox closed 6 months ago

paulocoutinhox commented 6 months ago

Hi,

I made a small dialog with FairyGUI Editor, but when use on AXMOL the title label and button position is different.

Editor Preview:

image

Editor:

image

Game:

image

Code:

// win dialog
fairygui::UIConfig::registerFont("Poppins-SemiBold", "fonts/Poppins-SemiBold.ttf");

groot = fairygui::GRoot::create(this);
groot->retain();
fairygui::UIPackage::addPackage("ui/dialog/dialog");

dialogWin = fairygui::UIPackage::createObject("MainPackage",
                                                "Main")->as<fairygui::GComponent>();
dialogWin->setPosition(Global::getInstance().visibleSize.width / 2 - dialogWin->getViewWidth() / 2, Global::getInstance().visibleSize.height / 2 - dialogWin->getViewHeight() / 2);
groot->addChild(dialogWin);

What im doing wrong?

paulocoutinhox commented 6 months ago

I tried create a Window like in tests Window1 example, but same problem:

fairygui::UIConfig::registerFont("Poppins-SemiBold", "fonts/Poppins-SemiBold.ttf");

groot = fairygui::GRoot::create(this);
groot->retain();

fairygui::UIPackage::addPackage("ui/dialog/dialog");

dialogWin = WinDialogWindow::create();
dialogWin->retain();
dialogWin->show();

WinDialogWindow.cpp:

#include "layers/WinDialogWindow.h"

using namespace fairygui;

void WinDialogWindow::onInit()
{
    setContentPane(UIPackage::createObject("MainPackage", "Main")->as<GComponent>());
    center();
}

void WinDialogWindow::onShown()
{
    //
}
image
paulocoutinhox commented 6 months ago

I stop using scale9 images and using now images with fixed size and it solve:

image