ccc 多点触控
研究了一天,多点触控的点无法保存,只能模拟多点触控了
cc.Class({
extends: cc.Component,
properties: {
wheelStick:{
default:null,
type:cc.Sprite
},
hero:
{
default:null,
type:cc.Sprite
},
wheelDir:
{
default:"null",
}
},
// use this for initialization
onLoad: function () {
this.registerInput();
this.test()
},
registerInput:function()
{
var self=this
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
//开始
onTouchBegan: function(touch, event) {
self.onTouchBegan(self,touch);
return true; // don't capture event
},
//移动
onTouchMoved: function(touch, event) {
self.onTouchMoved(self,touch);
},
//结束
onTouchEnded: function(touch, event) {
self.onTouchEnded(self,touch);
}
}, self.node);
},
onTouchBegan:function(self,touch)
{
//show
let touchPos=touch.getLocation()
if(touchPos.x<480)
{
let wheelPos=self.node.position
self.wheelStick.node.position=cc.pSub(touchPos,wheelPos)
//发射消息
self.wheelDir=self.figureDirFromTouchPoint(touchPos)
}
},
onTouchMoved:function(self,touch)
{
//show
let touchPos=touch.getLocation()
if(touchPos.x<480)
{
let wheelPos=self.node.position
self.wheelStick.node.position=cc.pSub(touchPos,wheelPos)
//发射消息
self.wheelDir=self.figureDirFromTouchPoint(touchPos)
}
},
onTouchEnded:function(self,touch)
{
self.wheelStick.node.position=cc.p(0,0)
self.wheelDir="null"
},
figureDirFromTouchPoint:function(touchPoint)
{
let cenPoint=this.node.position;
let arr=cc.pSub(touchPoint,cenPoint)
let angle=Math.atan2(arr.y,arr.x)* 180 / 3.14
if (angle <= 45 && angle > -45)
return "right"
if (angle <= -135 || angle > 135)
return "left"
if (angle >= 45 && angle < 135)
return "up"
if (angle <= -45 && angle >-135)
return "down"
},
update:function()
{
let dir=this.wheelDir
if(dir=="up")
this.hero.node.emit('wheelup', {
msg: '',
});
else if(dir=="down")
this.hero.node.emit('wheeldown', {
msg: '',
});
else if(dir=="left")
this.hero.node.emit('wheelleft', {
msg: '',
});
else if(dir=="right")
this.hero.node.emit('wheelright', {
msg: '',
});
},
test:function()
{
//测试角度
let tdd=require("TDD")
let cenPoint=this.node.position;
let tp1=cc.p(cenPoint.x+1,cenPoint.y+0)
tdd.assert("right"==this.figureDirFromTouchPoint(tp1),"figureDirFromTouchPoint1")
let tp2=cc.p(cenPoint.x+1,cenPoint.y+0.5)
tdd.assert("right"==this.figureDirFromTouchPoint(tp2),"figureDirFromTouchPoint2")
let tp3=cc.p(cenPoint.x+1,cenPoint.y-0.5)
tdd.assert("right"==this.figureDirFromTouchPoint(tp3),"figureDirFromTouchPoint3")
let tp4=cc.p(cenPoint.x+0,cenPoint.y+1)
tdd.assert("up"==this.figureDirFromTouchPoint(tp4),"figureDirFromTouchPoint4")
let tp5=cc.p(cenPoint.x+0.5,cenPoint.y+1)
tdd.assert("up"==this.figureDirFromTouchPoint(tp5),"figureDirFromTouchPoint5")
let tp6=cc.p(cenPoint.x-0.5,cenPoint.y+1)
tdd.assert("up"==this.figureDirFromTouchPoint(tp6),"figureDirFromTouchPoint6")
let tp7=cc.p(cenPoint.x+0,cenPoint.y-1)
tdd.assert("down"==this.figureDirFromTouchPoint(tp7),"figureDirFromTouchPoint7")
let tp8=cc.p(cenPoint.x+0.5,cenPoint.y-1)
tdd.assert("down"==this.figureDirFromTouchPoint(tp8),"figureDirFromTouchPoint8")
let tp9=cc.p(cenPoint.x-0.5,cenPoint.y-1)
tdd.assert("down"==this.figureDirFromTouchPoint(tp9),"figureDirFromTouchPoint9")
let tp10=cc.p(cenPoint.x-1,cenPoint.y+0)
tdd.assert("left"==this.figureDirFromTouchPoint(tp10),"figureDirFromTouchPoint10")
let tp11=cc.p(cenPoint.x-1,cenPoint.y+0.5)
tdd.assert("left"==this.figureDirFromTouchPoint(tp11),"figureDirFromTouchPoint11")
let tp12=cc.p(cenPoint.x-1,cenPoint.y-0.5)
tdd.assert("left"==this.figureDirFromTouchPoint(tp12),"figureDirFromTouchPoint12")
//测试发送消息
this.hero.node.emit('testmsg', {
msg: 'Hello, this is Cocos Creator',
});
},
});
ccc 多点触控的更多相关文章
- ccc 多点触控2
经过不断的思考发现,如果是两个sprite都添加触控的时候,往往直接成单点触控, 但是如果是两个node的时候在node上面点击就会变成多点触控的形式 cc.Class({ extends: cc.C ...
- [示例] Firemonkey OnTouch 多点触控应用
说明:Firemonkey OnTouch 多点触控应用,可同时多指移动多个不同控件 原码下载:[原创]TestMultitouchMove_多点触控应用_by_Aone.zip 运行展示:
- Cocos2dx 多点触控
1 最容易忽略的东西,对于ios平台,须得设置glView的属性: [__glView setMultipleTouchEnabled:YES]; 2 如果调用CCLayer的方法setTouchEn ...
- Android 多点触控与简单手势(一)
现在一般的Android手机都会使用电容触摸屏最少可以支持两点触摸,多的可能是七八个,所以基本上都会支持多点触控, android系统中应用程序可以使用多点触控的事件来完成各种手势和场景需求. And ...
- Android多点触控技术实战,自由地对图片进行缩放和移动
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/11100327 在上一篇文章中我带着大家一起实现了Android瀑布流照片墙的效果, ...
- MultiTouch————多点触控,伸缩图片,变换图片位置
前言:当今的手机都支持多点触控功能(可以进行图片伸缩,变换位置),但是我们程序员要怎样结合硬件去实现这个功能呢? 跟随我一起,来学习这个功能 国际惯例:先上DEMO免费下载地址:http://down ...
- windows8 开发教程 教你制作 多点触控Helper可将任意容器内任意对象进行多点缩放
http://blog.csdn.net/wangrenzhu2011/article/details/7732907 (转) 实现方法: 对Manipulation进行抽象化 使不同容器可共用多点缩 ...
- cocos2d-x 在xcode IOS模拟器中 开启IOS多点触控
在初始化代码中,开启当前层接受触摸 this->setTouchEnabled(true); 在AppController.mm文件中,设置开启多点触控 在- (BOOL)application ...
- Android 多点触控错误处理(java.lang.IllegalArgumentException: pointerIndex out of range)
最近做View的多点触控时,每次第一次触控事件完美运行,第二次就直接崩了,错误信息如下: 01-03 00:05:44.220 4377-4410/system_process E/AndroidRu ...
随机推荐
- Mysql分布式事务
关于Mysql分布式事务介绍,可参考:http://blog.csdn.net/luckyjiuyi/article/details/46955337 分为两个阶段:准备和执行阶段.有两个角色:事务的 ...
- Mysql 调用存储过程的两种方式
一,使用call语句: 如:创建 call 调用: 使用占位符,通过prepare,execute调用:
- Android错误:Re-installation failed due to different application signatures
Re-installation failed due to different application signatures (2013-04-20 14:27:32) 转载▼ 标签: 解决方法 问题 ...
- 根据复选框checkbox的选中状态来打开或关闭隐藏层
HTML: <input type="checkbox" id="check-expert"> <div id="expert&q ...
- postgresql集群方案参考答案
PostgreSQL配置Streaming Replication集群 http://www.cnblogs.com/marsprj/archive/2013/03/04/2943373.html p ...
- 四、优化及调试--网站优化--Yahoo军规上
什么是Yahoo军规?即如何提高网站速度的知识. 具体如下: 1.尽量减少HTTP请求个数——须权衡 什么是http请求:从客户端到服务器端的请求消息.包括消息首行中,对资源的请求方法,资源的标识符及 ...
- Deci and Centi Seconds parsing in java
http://stackoverflow.com/questions/14558663/deci-and-centi-seconds-parsing-in-java
- Delphi面向对象的可见性表示符
Delphi能通过在声明域和方法的时候用protected.private.public.published和automated指示符来对对象提供进一步的控制.使用这些关键字的语法如下 TSomeOb ...
- 编辑login.sql进行sqlplus登陆设置
执行SQLPLUS登录到SQL 界面时候,就会自动的加载 $ORACLE_HOME/sqlplus/admin 中的login.sql(若没有则加载glogin.sql) 这里面的东西 是根据自己的爱 ...
- TI Zigbee Light Link 参考设计
TI Zigbee Light Link 参考设计 原文出处: http://processors.wiki.ti.com/index.php/Category:ZigBee_Light_Link ...