Thursday, September 22, 2022
HomeGame DevelopmentThe best way to resolve this query - C++

The best way to resolve this query – C++


After I use the next code, I can see the “node2” sprite after operating this system.

	node2 = Sprite::create("ty.png");
	node2->setPosition(Vec2(700, 600));
	this->addChild(node2,5);
	auto listener = EventListenerKeyboard::create();
	listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Occasion* occasion) {
		keys[keyCode] = true;
	};
	listener->onKeyReleased = [=](cocos2d::EventKeyboard::KeyCode keyCode, Occasion* occasion) {
		keys[keyCode] = false;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
	this->scheduleUpdate();

However after I add the next code. I can’t see the “node2” sprite after operating this system.

	auto s = Director::getInstance()->getWinSize();
	auto pFollow = Observe::create(node2, Rect(0, 0, s.width + 3840, s.top)); 
	node2->runAction(pFollow);

Why?


With a purpose to facilitate debugging, I modified the next code, and output the display coordinate worth of node2 twice within the code. The code is as follows:

	node2 = Sprite::create("ty.png");
	node2->setPosition(Vec2(700, 700));
	this->addChild(node2,5);
	Vec2 b = this->node2->getPosition();
	CCLOG_VEC2(b);
	auto listener = EventListenerKeyboard::create();
	listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Occasion* occasion) {
		keys[keyCode] = true;
	};
	listener->onKeyReleased = [=](cocos2d::EventKeyboard::KeyCode keyCode, Occasion* occasion) {
		keys[keyCode] = false;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
	this->scheduleUpdate();
	
	auto s = Director::getInstance()->getWinSize();
	auto pFollow = Observe::create(node2, Rect(0, 0, s.width + 3840, s.top)); //3840是整个场景的宽
	node2->runAction(pFollow);
	Vec2 a = this->node2->getPosition();
	CCLOG_VEC2(a);

After executing the ‘Observe’ animation,
The output worth of the variable ‘b’ and the variable ‘a’ is identical, that’s to say, no matter whether or not the ‘Observe’ animation is executed or not, the coordinates output by the node2 node are the identical, and they’re all on the display.

On this case,
If the ‘Observe’ animation is just not added, the node2 node might be seen. After including the ‘Observe’ animation, why can’t the node2 node be seen after this system runs?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments