MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / init

Method init

Source/MenuGameLayer.cpp:54–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54bool MenuGameLayer::init(){
55 if (!Layer::init()) return false;
56
57 this->startPos = Vec2(0, 105);
58
59 auto dir = Director::getInstance();
60 const auto& winSize = dir->getWinSize();
61
62 groundLayer = GroundLayer::create(1);
63
64 addChild(groundLayer, 2);
65
66 //should work but doesnt?
67 auto playerTest = PlayerObject::create(GameToolbox::randomInt(1,14), this);
68 playerTest->setMainColor(GameToolbox::randomColor3B());
69 playerTest->setSecondaryColor(GameToolbox::randomColor3B());
70 playerTest->setPosition({-100, 93.f});
71 addChild(playerTest, 16);
72 this->player = playerTest;
73
74 const Texture2D::TexParams texParams = {
75 backend::SamplerFilter::LINEAR,
76 backend::SamplerFilter::LINEAR,
77 backend::SamplerAddressMode::REPEAT,
78 backend::SamplerAddressMode::REPEAT
79 };
80
81 bgSprites = Menu::create();
82
83 // this->bgSpr = bg;
84 // this->bgSpr->getTexture()->setTexParameters(texParams);
85 // this->bgSpr->setTextureRect(Rect(0, 0, 2048, 1024));
86 // this->bgSpr->setPosition(winSize / 2);
87
88 for(int i = 0; i < 4; i++) {
89 auto gr = Sprite::create(GameToolbox::getTextureString("game_bg_01_001.png"));
90 gr->setStretchEnabled(false);
91 gr->getTexture()->setTexParameters(texParams);
92 gr->setTextureRect(Rect(0, 0, 2048, 1024));
93 gr->setPosition(winSize / 2);
94 gr->setColor({ 0, 102, 255 });
95 // bg scale
96 gr->setScale(1.185f); // epic hardcore (please fix lmao)
97 bsizeX = gr->getContentSize().width;
98
99 this->bgSprites->addChild(gr);
100 }
101 this->bgSprites->alignItemsHorizontallyWithPadding(0);
102 this->bgStartPos = bgSprites->getPositionX();
103 this->addChild(bgSprites, -3);
104 sep = 0.3f;
105 bgSprites->setScale(winSize.width / bgSprites->getContentSize().width);
106 bgSprites->setPositionY(0);
107
108 //this is not how it works lol
109 // bgSprites->setColor(GameToolbox::randomColor3B());
110
111 // // this->addChild(this->bgSpr, -1);

Callers 1

createMethod · 0.45

Calls 8

createFunction · 0.85
setPositionMethod · 0.80
setScaleMethod · 0.80
Vec2Class · 0.70
setMainColorMethod · 0.45
setSecondaryColorMethod · 0.45
setColorMethod · 0.45

Tested by

no test coverage detected