Tuesday, April 16, 2024
HomeSample Page

Sample Page Title


When I exploit the next code, I can see the “node2” sprite after working 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, Event* occasion) {
		keys[keyCode] = true;
	};
	listener->onKeyReleased = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* occasion) {
		keys[keyCode] = false;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
	this->scheduleUpdate();

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

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

Why?

In order 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, Event* occasion) {
		keys[keyCode] = true;
	};
	listener->onKeyReleased = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* occasion) {
		keys[keyCode] = false;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
	this->scheduleUpdate();
	
	auto s = Director::getInstance()->getWinSize();
	auto pFollow = Follow::create(node2, Rect(0, 0, s.width + 3840, s.peak)); //3840是整个场景的宽
	node2->runAction(pFollow);
	Vec2 a = this->node2->getPosition();
	CCLOG_VEC2(a);

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

In this case,
If the ‘Follow’ animation will not be added, the node2 node could be seen. After including the ‘Follow’ animation, why can’t the node2 node be seen after this system runs?

I’m unsure what you imply by “follow animation”, however the comply with motion you’ve created seems to be incorrect, because you’re making node2 comply with itself.

The cpp-tests challenge has quite a few examples of appropriate utilization.

Try altering this:
node2->runAction(pFollow);
to this
this->runAction(pFollow);

Please select a greater title!

after modified like this:

this->runAction(pFollow);

It is okay now,thanks.
I’ve a one other query,please have a look at right here:
https://focus on.cocos2d-x.org/t/is-it-possible-to-perform-a-sequence-frame-animation-without-adding-every-frame/57230/2

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments