Sunday, September 11, 2022
HomeGame DevelopmentNewbie information to desktop controller enter? - cocos2d-x

Newbie information to desktop controller enter? – cocos2d-x


good day,
I’ve search quite a bit in google and this discussion board about the way to enter a gamepad controller, however didn’t actually succed to comply with the way to truly make it work. Some subject are very previous, and another have snippets of code that didn’t actually assist.
Can somebody present some newbie code to make it work please? I attempted with a quite simple take a look at. All I need is to see if the occasion is triggered after I press down one thing.

#embody <CCGameController.h>
USING_NS_CC;

//....

void Participant::gamePadListener()
{
	Controller::startDiscoveryController();

	auto eventListenerController = EventListenerController::create();

	eventListenerController->onKeyDown = [=](cocos2d::Controller* controller, int key_code, cocos2d::Occasion* evt) {
        CCLOG("gamepad key pressed %i", key_code);
    };

	this->_eventDispatcher->addEventListenerWithSceneGraphPriority(eventListenerController, this);

}

I get the next:

ControllerImpl: Couldn't discover a button enter map for controller: Xbox Controller
ControllerImpl: Couldn't discover an axis enter map for controller: Xbox Controller

Does that signifies that it solely works with an Xbox Controller or am I doing one thing improper? I’ve tried this with 2 controllers: one, the xbox one wi-fi controller, an two a nacom controller (so a random controller).

Can somebody present some “information for dummys” . Many subject about it appear to be already within the assumptions on how all this works. How can we make any controller work on home windows, mac or linux?? is that this too complicated to attain with cocos2dx? As a result of clearly, each consumer have a special sort of controller. I’m even taking part in video games with the ps5 controller on computer.

And one final thing. They keyboard occasion listener works completely fantastic. I’ve somthing like this

void Participant::createEventListenerKeyboard()
{
	auto eventListenerKeyboard = EventListenerKeyboard::create();  // hacer attr privado?
	eventListenerKeyboard->onKeyPressed = [=](EventKeyboard::KeyCode code, Occasion* occasion) {
        //....some code
        }      
	this->_eventDispatcher->addEventListenerWithSceneGraphPriority(eventListenerKeyboard, GameGlobals::playerSprite);
}

my query is in regards to the final line.

	this->_eventDispatcher->addEventListenerWithSceneGraphPriority(eventListenerKeyboard, GameGlobals::playerSprite);

if return to the controller code and do that

// this does not crash
// this->_eventDispatcher->addEventListenerWithSceneGraphPriority(eventListenerController, this);  

// this crashes
this->_eventDispatcher->addEventListenerWithSceneGraphPriority(eventListenerController, GameGlobals::playerSprite);

then the sport crashes earlier than it begins with the error

Program: ...inbinspaceShooter_0.1DebugspaceShooter_0.1.exe
File: D:CHIMERA STUDIOCHIMERA GAMESlea...CCEvent...her.cpp
Line: 504

Expression: listener && node

For info on how your program could cause an assertion
failure, see the Visible C++ documentation on asserts

so why utilizing GameGlobals::playerSprite crashes for the controller, however works fantastic within the keyboard?

Any, I hope somebody shed some mild on this as a result of I’m about to publish my first sport and I can’t if I don’t work out all this.

thanks prematurely

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments