SneakyInput for Cocos2d-x

Source: Internet
Author: User

SneakyInput is a virtual joystick library. SneakyInput is the virtual handle in 2dx. But the 2dx version downloaded from the official website is too old, to modify him, applicable to cocos2d-x 2.1.4 version. In theory, it applies to all 2dx versions 2.1 +. Go to the topic: [cpp] # include "SneakyInput/SneakyJoystickSkinnedBase. h "# include" SneakyInput/SneakyButtonSkinnedBase. h "SneakyButton * button; SneakyJoystick * joystick; defines the SneakyInput joystick and obtains the joystick data. Definition: [cpp] SneakyJoystickSkinnedBase * joystickBase = new kernel (); joystickBase-> autorelease (); joystickBase-> init (); joystickBase-> setBackgroundSprite (CCSprite: create ("B .png"); // Base JoystickBase-> setThumbSprite (CCSprite: create ("f.png"); // joystickBase-> setPosition (CCPointMake (48, 48); joystickBase = new SneakyJoystick (); joystick-> autorelease (); joystick-> initWithRect (CCRectMake (, 64); joystickBase-> setJoystick (joystick ); // whether to automatically return to the center joystick-> setAutoCenter (true); // whether the dead zone is supported. joystick-> setHasDeadzone (true) is not triggered in this region ); // death zone radius joystick-> setDeadRadius (10); this-> addChild (JoystickBase); get data: [cpp] joystick-> getVelocity (); Define the button of SneakyInput and the data of the get button: Define button: [cpp] <span style = "white-space: pre"> </span> // button skin SneakyButtonSkinnedBase * buttonBase = new SneakyButtonSkinnedBase (); buttonBase-> autorelease (); buttonBase-> init (); buttonBase-> setdefasprsprite (CCSprite: create ("default.png"); buttonBase-> setActivatedSprite (CCSprite: create ("activated.png ")); buttonBase-> setPre SsSprite (CCSprite: create ("press.png"); buttonBase-> setPosition (CCPointMake (480-48, 48); // button = new SneakyButton (); button-> autorelease (); button-> initWithRect (CCRectMake (, 32, 32); button-> setIsToggleable (false); // when you press the button, whether to keep the following status: button-> setIsHoldable (true); buttonBase-> setButton (button); this-> addChild (buttonBase); get data: [cpp] button-> getIsActive (); // If the button is pressed, the data is generally obtained in update (float dt. [Cpp] void HelloWorld: update (float dt) {if (button-> getIsActive () {CCLog ("fire! ");} CCPoint scaledV = ccpMult (joystick-> getVelocity (), 1); float x = scaledV. x; float y = scaledV. y; CCLog ("% f --- % f", x, y );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.