I am trying to create buttons that will function as a D-pad to allow the player to move the character using a ccui.Button. I am trying to respond to the methods onPressStateChangedToNormal()
and onPressStateChangedToPressed()
. I however cannot figure out how to respond to the callbacks. My current attempt is by using the method as a variable and assigning my own function, which results in cc.log not being called.
My code is as follows:
this.btnUp = new ccui.Button();
this.btnUp.loadTextureNormal(res.arrowUp_png, null);
this.btnUp.setPosition(100, 100);
this.btnUp.onPressStateChangedToPressed = function(){ cc.log("btnUp pressed!"); };
The value of res.arrowUp_png
is "res/arrow-up.png"
.
If a different type of button is more suited for my use case, I’d be happy to switch implementations. For now, I either want to log a message every time the game updates while the button is pressed, or to log a message when the button has been pressed and released.