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

Method initWithTargetAndOffset

core/2d/Action.cpp:213–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211}
212
213bool Follow::initWithTargetAndOffset(Node* followedNode, float xOffset, float yOffset, const Rect& rect)
214{
215 AXASSERT(followedNode != nullptr, "FollowedNode can't be NULL");
216 if (followedNode == nullptr)
217 {
218 AXLOGE("Follow::initWithTarget error: followedNode is nullptr!");
219 return false;
220 }
221
222 followedNode->retain();
223 _followedNode = followedNode;
224 _worldRect = rect;
225 _boundarySet = !rect.equals(Rect::ZERO);
226 _boundaryFullyCovered = false;
227
228 Vec2 winSize = Director::getInstance()->getWinSize();
229 _fullScreenSize.set(winSize.width, winSize.height);
230 _halfScreenSize = _fullScreenSize * 0.5f;
231 _offsetX = xOffset;
232 _offsetY = yOffset;
233 _halfScreenSize.x += _offsetX;
234 _halfScreenSize.y += _offsetY;
235
236 if (_boundarySet)
237 {
238 _leftBoundary = -((rect.origin.x + rect.size.width) - _fullScreenSize.x);
239 _rightBoundary = -rect.origin.x;
240 _topBoundary = -rect.origin.y;
241 _bottomBoundary = -((rect.origin.y + rect.size.height) - _fullScreenSize.y);
242
243 if (_rightBoundary < _leftBoundary)
244 {
245 // screen width is larger than world's boundary width
246 // set both in the middle of the world
247 _rightBoundary = _leftBoundary = (_leftBoundary + _rightBoundary) / 2;
248 }
249 if (_topBoundary < _bottomBoundary)
250 {
251 // screen width is larger than world's boundary width
252 // set both in the middle of the world
253 _topBoundary = _bottomBoundary = (_topBoundary + _bottomBoundary) / 2;
254 }
255
256 if ((_topBoundary == _bottomBoundary) && (_leftBoundary == _rightBoundary))
257 {
258 _boundaryFullyCovered = true;
259 }
260 }
261
262 return true;
263}
264
265bool Follow::initWithTarget(Node* followedNode, const Rect& rect /*= Rect::ZERO*/)
266{

Callers 1

createWithOffsetMethod · 0.80

Calls 4

getInstanceFunction · 0.85
retainMethod · 0.45
equalsMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected