zoukankan      html  css  js  c++  java
  • ccc 多点触控2

    经过不断的思考发现,如果是两个sprite都添加触控的时候,往往直接成单点触控,
    但是如果是两个node的时候在node上面点击就会变成多点触控的形式
    
    cc.Class({
        extends: cc.Component,
    
        properties: {
            isAPress:false,
            aLabel:
            {
                default:null,
                type   :cc.Label
            }
        },
    
        // use this for initialization
        onLoad: function () {
    
            this.isAPress=false
    
            this.registerInput();
    
        },
    
        registerInput:function()
        {
            var self=this
    
            cc.eventManager.addListener({
                event: cc.EventListener.TOUCH_ONE_BY_ONE,
    
                //开始
                onTouchBegan: function(touch, event) {
                          
                    let touchPos=touch.getLocation()
                    if(touchPos.x<480)
                    {
                        self.isAPress=true
                    }
                    return true; // don't capture event
                },
    
                //移动
                onTouchMoved: function(touch, event) {
                    let touchPos=touch.getLocation()
                    if(touchPos.x<480)
                    {
                        self.isAPress=true
                    }   
                },
    
                //结束
                onTouchEnded: function(touch, event) {
                    self.isAPress=false
                }
            }, self.node);
        },
    
        update:function()
        {
            if(this.isAPress)
            {
                this.aLabel.string = "1"
            }
            else
            {
                this.aLabel.string = "0"
            }
        },
    
    
    
    });
    
  • 相关阅读:
    202. Happy Number
    198. House Robber
    191. Number of 1 Bits
    190. Reverse Bits
    189. Rotate Array
    172. Factorial Trailing Zeroes
    171. Excel Sheet Column Number
    [leetcode]Single Number II
    [leetcode]Single Number
    [leetcode]Clone Graph
  • 原文地址:https://www.cnblogs.com/yufenghou/p/5617005.html
Copyright © 2011-2022 走看看