MCPcopy Create free account
hub / github.com/axmolengine/axmol / captureNode

Function captureNode

core/base/Utils.cpp:132–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130
131static std::unordered_map<Node*, EventListenerCustom*> s_captureNodeListener;
132void captureNode(Node* startNode, std::function<void(RefPtr<Image>)> imageCallback, float scale)
133{
134 if (s_captureNodeListener.find(startNode) != s_captureNodeListener.end())
135 {
136 AXLOGW("Warning: current node has been captured already");
137 return;
138 }
139
140 auto callback = [startNode, scale, imageCallback](EventCustom* /*event*/) {
141 auto director = Director::getInstance();
142 auto captureNodeListener = s_captureNodeListener[startNode];
143 director->getEventDispatcher()->removeEventListener((EventListener*)(captureNodeListener));
144 s_captureNodeListener.erase(startNode);
145 auto& size = startNode->getContentSize();
146
147 director->setNextDeltaTimeZero(true);
148
149 RenderTexture* finalRtx = nullptr;
150
151 auto rtx =
152 RenderTexture::create(size.width, size.height, backend::PixelFormat::RGBA8, PixelFormat::D24S8, false);
153 // rtx->setKeepMatrix(true);
154 Point savedPos = startNode->getPosition();
155 Point anchor;
156 if (!startNode->isIgnoreAnchorPointForPosition())
157 {
158 anchor = startNode->getAnchorPoint();
159 }
160 startNode->setPosition(Point(size.width * anchor.x, size.height * anchor.y));
161 rtx->begin();
162 startNode->visit();
163 rtx->end();
164 startNode->setPosition(savedPos);
165
166 if (std::abs(scale - 1.0f) < 1e-6f /* no scale */)
167 finalRtx = rtx;
168 else
169 {
170 /* scale */
171 auto finalRect = Rect(0, 0, size.width, size.height);
172 Sprite* sprite = Sprite::createWithTexture(rtx->getSprite()->getTexture(), finalRect);
173 sprite->setAnchorPoint(Point(0, 0));
174 sprite->setFlippedY(true);
175 finalRtx = RenderTexture::create(size.width * scale, size.height * scale, backend::PixelFormat::RGBA8,
176 PixelFormat::D24S8, false);
177
178 sprite->setScale(scale); // or use finalRtx->setKeepMatrix(true);
179 finalRtx->begin();
180 sprite->visit();
181 finalRtx->end();
182 }
183
184 director->getRenderer()->render();
185
186 finalRtx->newImage(imageCallback);
187 };
188
189 auto listener =

Callers 2

onCapturedMethod · 0.85

Calls 15

getInstanceFunction · 0.85
createFunction · 0.85
setNextDeltaTimeZeroMethod · 0.80
getAnchorPointMethod · 0.80
getRendererMethod · 0.80
newImageMethod · 0.80
PointClass · 0.50
absFunction · 0.50
RectFunction · 0.50
findMethod · 0.45

Tested by 1

onCapturedMethod · 0.68