forked from lshain/SneakyInput-Cocos2dx-3.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SneakyJoystick.h
48 lines (38 loc) · 1.45 KB
/
SneakyJoystick.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef __SNEAKY_JOYSTICK_H__
#define __SNEAKY_JOYSTICK_H__
#include "cocos2d.h"
class SneakyJoystick : public cocos2d::CCNode
{
private:
cocos2d::EventListenerTouchOneByOne * mEventListenerTouch;
protected:
float joystickRadiusSq;
float thumbRadiusSq;
float deadRadiusSq;
CC_SYNTHESIZE_READONLY(cocos2d::CCPoint, stickPosition, StickPosition);
CC_SYNTHESIZE_READONLY(float, degrees, Degrees);
CC_SYNTHESIZE_READONLY(cocos2d::CCPoint, velocity, Velocity);
CC_SYNTHESIZE(bool, autoCenter, AutoCenter);
CC_SYNTHESIZE_READONLY(bool, isDPad, IsDPad);
CC_SYNTHESIZE(bool, hasDeadzone, HasDeadzone);
CC_SYNTHESIZE(int, numberOfDirections, NumberOfDirections);
CC_SYNTHESIZE_READONLY(float, joystickRadius, JoystickRadius);
CC_SYNTHESIZE_READONLY(float, thumbRadius, ThumbRadius);
CC_SYNTHESIZE_READONLY(float, deadRadius, DeadRadius);
virtual ~SneakyJoystick();
bool initWithRect(cocos2d::CCRect rect);
virtual void onEnterTransitionDidFinish();
virtual void onExit();
void setIsDPad(bool b);
void setJoystickRadius(float r);
void setThumbRadius(float r);
void setDeadRadius(float r);
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchCancelled(cocos2d::Touch* touch, cocos2d::Event* event);
private:
void updateVelocity(cocos2d::CCPoint point);
void setTouchRadius();
};
#endif