Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17076

How to pass a function a parameter to a method?

$
0
0

@katieJ wrote:

I'm quite new to cocos2dx and want to be able to pass a function to be called as a parameter to a method. I think I probably need to understand Lambda's but would love some help. Here is my existing function:

void SettingsModal::animateOut() {
	auto modal = this->getModal();
	if (modal) {
		// move the sprite down the screen
		float moveDownBy = C_SCREEN->getCentre().y + modal->getContentSize().height/2;
		auto moveBy = MoveBy::create(0.5, Vec2(0, -moveDownBy));

		// call this method at the end.
		auto func = CallFuncN::create([=](Ref* sender) {
			ModalLayer::close(sender);
		});

		// sequence up and run.
		auto sequence = Sequence::create(moveBy, func, nullptr);
		modal->runAction(sequence);
	}
}

I would like to be able to pass in to the animateOut method the function that I want it to call after the animation completes. In objective-c I would use a block? I don't want to embed the call to "ModalLayer::close()" as it's coupling to much for my design.

Thanks in advance.

Katie

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17076

Trending Articles