LayaAir 游戏引擎 多点触控演示

编程入门 行业动态 更新时间:2024-10-09 03:24:37

LayaAir 游戏引擎 <a href=https://www.elefans.com/category/jswz/34/1761904.html style=多点触控演示"/>

LayaAir 游戏引擎 多点触控演示

最近发现LayaAir 引擎示例 对触控介绍的很少

所以写了一个多点触控的小例子 

这里例子需要在手机浏览器下才能看到效果

希望可以和大家分享一下

先准备一个圆形 模拟触控效果

class Round extends Laya.Sprite{private timeLine:Laya.TimeLine = new Laya.TimeLine();private count:number;constructor(){super();}show(){this.graphics.drawCircle(0, 0, 45, "#ff0000");console.log("init");}hide(){console.log("start");this.timeLine.addLabel("zoom",0).to(this,{scaleX:3, scaleY:3, alpha:0},500,null,0);this.timeLine.play(0,true);this.timeLine.on(Laya.Event.COMPLETE,this,this.onComplete);}private onComplete():void{this.timeLine.offAll();this.removeSelf();}
}

1. 首先定义 五个手指的数组 当然 如果你想两只手都上 或者加上脚趾 20个也是可以的!

private rounds:Array<Round> = [null,null,null,null,null];

2. 添加对鼠标的按下和抬起的监听

Laya.stage.on(Laya.Event.MOUSE_DOWN,this,this.mouseDown);
Laya.stage.on(Laya.Event.MOUSE_UP,this,this.mouseUp);

3.在触控点显示一个圆形进行控制 释放时放大并圆形消失

    mouseDown(e:Laya.Event){var touches: Array<any> = e.touches;let round:Round = new Round();round.pos(Laya.stage.mouseX,Laya.stage.mouseY);Laya.stage.addChild(round);this.rounds[e.touchId] = round;round.show(); }mouseUp(e:Laya.Event){console.info(e);this.rounds[e.touchId].hide();}

实现的思路就是使用e.touchId来决定触控点的index 

另外 e.touches 中的数据 只有在触控的时候才有数据,  如果需要做更多操作 还需要获取其中的属性 进行操作 

测试的时候可以使用浏览器中的模拟触控


最后为e.touches 列表中 touche 包含的属性

    1. clientX:174
    2. clientY:299
    3. force:1
    4. identifier:0
    5. pageX:174
    6. pageY:299
    7. radiusX:11.5
    8. radiusY:11.5
    9. rotationAngle:0
    10. screenX:657
    11. screenY:471
    12. stageX:174
    13. stageY:299
    14. target:canvas#layaCanvas

更多推荐

LayaAir 游戏引擎 多点触控演示

本文发布于:2024-02-27 19:43:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1765794.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多点   演示   触控   引擎   游戏

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!