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

Method updateCamera

Source/LevelEditorLayer.cpp:61–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59// LevelEditorLayer* LevelEditorLayer::getInstance() {}
60
61void LevelEditorLayer::updateCamera(float dt) {
62 if (_inPlaybackMode) {
63 PlayLayer::updateCamera(dt);
64
65 this->_bottomGround->setPositionX(cameraFollow->getPositionX());
66
67 _button_playback->setPositionX(cameraFollow->getPositionX() + 30);
68 _button_playback->setPositionY(cameraFollow->getPositionY() + 30);
69
70 return;
71 }
72
73 extern float gameSpeed;
74
75 dt /= gameSpeed;
76
77 ax::Vec2 cam2 = m_camDelta;
78
79 cam2.x *= dt;
80 cam2.y *= dt;
81
82 m_obCamPos += cam2;
83
84 auto winSize = ax::Director::getInstance()->getWinSize();
85 ax::Vec2 cam = m_obCamPos;
86
87 cam.y = ax::clampf(cam.y, 0.0f, 1140.f - winSize.height);
88
89 this->m_pBG->setPositionX(this->m_pBG->getPositionX() + (cam.x - m_obCamPos.x));
90
91 if (!this->m_bMoveCameraX)
92 m_obCamPos.x = cam.x;
93
94 // if camera reset then do not lerp
95 if (!this->m_bMoveCameraY && cam.x != 0)
96 {
97 m_obCamPos.y = GameToolbox::iLerp(m_obCamPos.y, cam.y, 0.1f, dt / 60.f);
98 }
99 else
100 {
101 m_obCamPos.y = cam.y;
102 }
103
104 ax::Camera::getDefaultCamera()->setPosition(this->m_obCamPos + winSize / 2);
105
106 cameraFollow->setPosition(m_obCamPos);
107
108 m_pHudLayer->setPosition(this->m_obCamPos);
109
110 cam2.x *= 0.5;
111 cam2.x *= 0.5;
112
113 cam2.x = -cam2.x;
114
115 this->m_pBG->setPositionX(this->m_pBG->getPositionX() - (cam2.x) * _bottomGround->getSpeed() * 0.1175f);
116
117 _bottomGround->update(-cam2.x * 0.7);
118 _ceiling->update(-cam2.x * 0.7);

Callers 1

initMethod · 0.95

Calls 2

setPositionMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected