Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

求,这个触摸事件的代码没报错,但是模拟器运行却没有任何效果

$
0
0

@Daguidwn 写道:

这个是js脚本,挂在canvas的,运行时控制台没有报错。我想实现的是:当触摸屏幕左边时,预制资源C1在X方向上向右加速。但是无论我怎么点击屏幕,那个C1的运动速度都不会改变,请大神帮忙看看哪里写错了,我把涉及到触摸事件的代码贴在下面:

onLoad: function () {

    var isTouch = false;
    this.isTouch = isTouch;
    this.node.on('touchstart',function (event) {
        var Touches = event.getTouches();
        var TouchX = Touches[0].getLocationX();
        this.TouchX = TouchX;
        this.isTouch = true;
    },this.node);

},

update: function (dt) {

    if (this.isTouch) {
        this.MoveSpeed += 200 * dt;
        if ((cc.view.getVisibleSize().width / 2) > this.TouchX) {
            if (this.MoveSpeed <= this.MoveSpeedMax) {
                this.C1XSpeed += 200 * dt;
            }
        }
        else {
            if (this.MoveSpeed <= this.MoveSpeedMax) {
                this.C1XSpeed -= 200 * dt;
            }
        }
    }
    
    this.C1.x += this.C1XSpeed * dt;
    this.C1.y += this.FaSpeed * dt;

},

帖子: 1

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>