关于cocos2dx虚拟摇杆的lua实现
来源:互联网 发布:淘宝下拉框关键词 编辑:程序博客网 时间:2024/06/06 06:47
看到网上不少虚拟摇杆的代码,但是都是在c++里面实现,非常不方便,所以我自己把c++的代码移植到lua里面
local VitrualController = class("VitrualController", cc.Layer)function VitrualController:ctor(app, name) if self.onCreate then self:onCreate() endendfunction VitrualController:onTouchesEnded(touches, event ) self:_deactive()endfunction VitrualController:onTouchesBegan(touches, event ) self.start_pos = cc.p(touches[1]:getLocation())self:_active(self.start_pos)endfunction VitrualController:onTouchesMove(touches, event ) local pos = cc.p(touches[1]:getLocation()) local distance = cc.pGetDistance(self.start_pos,pos) local direction = cc.pNormalize(cc.pSub(pos,self.start_pos)) self:_update(direction,distance)endfunction VitrualController:onCreate() self.joystick = cc.Sprite:create( "res/Joystick_03.png") self.joystick:setScale(0.2,0.2) self.joystick_bg = cc.Sprite:create( "res/Back_04.png") self.joystick_bg:setScale(0.3,0.3) self:addChild(self.joystick_bg) self:addChild(self.joystick) local listener = cc.EventListenerTouchAllAtOnce:create() listener:registerScriptHandler(function(...) self:onTouchesBegan(...) end,cc.Handler.EVENT_TOUCHES_BEGAN ) listener:registerScriptHandler(function(...) self:onTouchesEnded(...) end,cc.Handler.EVENT_TOUCHES_ENDED ) listener:registerScriptHandler(function(...) self:onTouchesMove(...) end,cc.Handler.EVENT_TOUCHES_MOVED ) local eventDispatcher = self:getEventDispatcher() eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)endfunction VitrualController:_active(pos) self.joystick:setPosition(pos) self.joystick_bg:setPosition(pos) self.joystick:setVisible(true) self.joystick_bg:setVisible(true)endfunction VitrualController:_deactive(pos) self.joystick:setVisible(false) self.joystick_bg:setVisible(false)endfunction VitrualController:_update(direction,distance) print("seayoung udpate",direction.x,direction.y,distance) local start = cc.p(self.joystick_bg:getPosition()) if distance < 32 then self.joystick:setPosition(cc.pAdd(start , (cc.pMul(direction ,distance)))) else if distance > 96 then self.joystick:setPosition(cc.pAdd(start , (cc.pMul(direction ,64)))) else self.joystick:setPosition(cc.pAdd(start , (cc.pMul(direction ,32)))) endendendreturn VitrualController
1 0
- 关于cocos2dx虚拟摇杆的lua实现
- cocos2dx-3.4虚拟摇杆的实现
- cocos2dx-3.10虚拟摇杆的实现
- quick-lua 实现 虚拟摇杆
- cocos2dx之虚拟摇杆
- UGUI 虚拟摇杆的实现
- unity虚拟摇杆的实现
- 基于Unity3D的虚拟摇杆的实现
- android虚拟手柄摇杆的实现
- Cocos2d-js3.3 虚拟摇杆的实现
- Cocos2d-js3.3虚拟摇杆的实现
- Unity3d 基于NGUI的虚拟摇杆实现
- Unity Joystick 虚拟摇杆的实现
- Unity_虚拟摇杆的实现_065
- 通过surfaceView实现的虚拟摇杆控制
- Unity3D基于UGUI的虚拟摇杆实现
- Unity中虚拟摇杆的简单实现
- quick实现虚拟摇杆
- 图片淡入淡出效果
- tomcat内存溢出
- 轻量级数据缓存
- Android 软键盘的显示和隐藏
- PSA分区达到最大报错(表RSTSODS很有用)
- 关于cocos2dx虚拟摇杆的lua实现
- Linux下tomcat设置最大连接数
- [iuud8]STL之vector
- 使用新浪SAE和PHPthink遇到的坑总结
- CodeForces 612C Replace To Make Regular Bracket Sequence (栈)
- 监控工具netdata在CentOS上部署
- Android进阶处理图片之压缩图片大小、Lru内存解决方案
- 杭电hdOJ1982 Kaitou Kid - The Phantom Thief (1)
- Thread.Sleep(1000) 、Task.Delay(1000).Wait() 区别