编译成android才会出现问题

问题就是,控制一个角色跳跃,用做h5就没有问题。可是编译成apk后在手机上运行就会出现 跳跃按钮有响应 但是经常没有实现跳跃。 其实我想说的是发布在安卓平台经常出问题,而h5就不会。 希望解决这种不协调啊啊啊啊啊。

能否弄一个简单的 demo 上传上来,理论上不会出现你说的这种错误。

从官方的示例修改的,按 j 跳跃

cc.Class({
extends: cc.Component,
properties: {
speed: cc.v2(0, 0),
maxSpeed: cc.v2(800, 12000),
gravity: -4000,
drag: 3000,
direction: 0,
jumpSpeed: 3600,
bulletP: {

        default : null,
        type : cc.Prefab

    },
    monsterBulletP: {

        default : null,
        type : cc.Prefab

    },
},

onLoad: function () {
    cc.director.getCollisionManager().enabled = true;
    // cc.director.getCollisionManager().enabledDebugDraw = true;
    
    cc.eventManager.addListener({
        event: cc.EventListener.KEYBOARD, 
        onKeyPressed: this.onKeyPressed.bind(this),
        onKeyReleased: this.onKeyReleased.bind(this),
    }, this.node);
    
    this.collisionX = 0;
    this.collisionYY = 0;

    // this.prePosition = cc.v2();
    // this.preStep = cc.v2();

    // this.touchingNumber = 0;

    this.bulletroot = cc.find('bulletRoot');

    this.heromotion = cc.find('heroMotion');

    
    this.monstersS = cc.find('monsters').getComponentsInChildren ( cc.Sprite) ;

    this.monstersC = cc.find('monsters').getComponentsInChildren ( "monsterC") ;
  
    this.monstersY = new Array();
    for (var i = 0; i <this.monstersS.length; i++)
    {
             this.monstersY[i] = this.monstersS[i].node.y;

            
    }


    

},

onDisabled: function () {
    cc.director.getCollisionManager().enabled = false;
    // cc.director.getCollisionManager().enabledDebugDraw = false;
},

jumpcontrol : function(){

    if (!this.jumping) {
                this.jumping = true;
                this.speed.y = this.jumpSpeed;    
            }
            
},

r: function(){
    this.node.scaleX = 1;
},

l: function(){
    this.node.scaleX = -1;
},

instantiateBullet : function (){

    var bullet = cc.instantiate(this.bulletP);
    bullet.parent = this.bulletroot;
            


},

onKeyPressed: function (keyCode, event) {
    switch(keyCode) {
        case cc.KEY.a:
        case cc.KEY.left:
            this.direction = -1;
            this.node.scaleX = -1;
            break;
        case cc.KEY.d:
        case cc.KEY.right:
            this.direction = 1;
            this.node.scaleX = 1;
            break;
        case cc.KEY.h:
            this.instantiateBullet();
            break;
        case cc.KEY.w:
        case cc.KEY.up:
        case cc.KEY.j:
            if (!this.jumping) {
                this.jumping = true;
                this.speed.y = this.jumpSpeed;    
            }
            break;
    }
},

onKeyReleased: function (keyCode, event) {
    switch(keyCode) {
        case cc.KEY.a:
        case cc.KEY.left:
        case cc.KEY.d:
        case cc.KEY.right:
            this.direction = 0;
            break;
    }
},

onCollisionEnter: function (other, self) {


    // this.node.color = cc.Color.RED;

    if(other.node.group == 'bulletorattackfrommons'){

        var bg = cc.find('bgmove');

        bg.runAction(cc.sequence(
         
         cc.moveBy(0.01,20,0),
         cc.moveBy(0.02,-40,0),
         cc.moveBy(0.01,20,0)
    ).repeat(5));

    }

    // this.touchingNumber ++;
    
    var otherAabb = other.world.aabb;
    var selfAabb = self.world.aabb.clone();
    var preAabb = self.world.preAabb;
    
    selfAabb.x = preAabb.x;
    selfAabb.y = preAabb.y;

    selfAabb.x = self.world.aabb.x;
    if (cc.Intersection.rectRect(selfAabb, otherAabb)) {
        if (this.speed.x < 0 && (selfAabb.xMax > otherAabb.xMax)) {
            this.node.x = otherAabb.xMax+this.node.width/2;
            this.collisionX = -1;
        }
        else if (this.speed.x > 0 && (selfAabb.xMin < otherAabb.xMin)) {
            this.node.x = otherAabb.xMin-this.node.width/2;
            this.collisionX = 1;
        }

        this.speed.x = 0;
        other.touchingX = true;
        return;
    }

    selfAabb.y = self.world.aabb.y;
    if (cc.Intersection.rectRect(selfAabb, otherAabb)) {
        if (this.speed.y < 0 && (selfAabb.yMax > otherAabb.yMax)) {
            this.node.y = otherAabb.yMax+this.node.height/2;
            this.jumping = false;
            this.collisionYY = -1;
        }
        else if (this.speed.y > 0 && (selfAabb.yMin < otherAabb.yMin)) {
            this.node.y = otherAabb.yMin - selfAabb.height/2-10;  //ru guo ba -10 qv diao hui chu xian dao gua
            this.collisionYY = 1;
        }
        
        this.speed.y = 0;
        other.touchingY = true;
    }    
    
},

onCollisionStay: function (other, self) {
    if (this.collisionYY === -1) {
        var offset = cc.v2(other.world.aabb.x - other.world.preAabb.x, 0);
        
        var temp = cc.affineTransformClone(self.world.transform);
        temp.tx = temp.ty = 0;
        
        offset = cc.pointApplyAffineTransform(offset, temp);
        this.node.x += offset.x;
    }
},

onCollisionExit: function (other) {
    // this.touchingNumber --;
    // if (this.touchingNumber === 0) {
    //     this.node.color = cc.Color.WHITE;
    // }

    if (other.touchingX) {
        this.collisionX = 0;
        other.touchingX = false;
    }
    else if (other.touchingY) {
        other.touchingY = false;
        this.collisionYY = 0;
        this.jumping = true;
    }
},

update: function (dt) {
   if (this.collisionYY === 0) {
        this.speed.y += this.gravity * dt;
        if (Math.abs(this.speed.y) > this.maxSpeed.y) {
            this.speed.y = this.speed.y > 0 ? this.maxSpeed.y : -this.maxSpeed.y;
        }
    }


    if (this.direction === 0) {
        if (this.speed.x > 0) {
            this.speed.x -= this.drag * dt;
            if (this.speed.x <= 0) this.speed.x = 0;
        }
        else if (this.speed.x < 0) {
            this.speed.x += this.drag * dt;
            if (this.speed.x >= 0) this.speed.x = 0;
        }
    }
    else {
        this.speed.x += (this.direction > 0 ? 1 : -1) * this.drag * dt;
        if (Math.abs(this.speed.x) > this.maxSpeed.x) {
            this.speed.x = this.speed.x > 0 ? this.maxSpeed.x : -this.maxSpeed.x;
        }
    }

    if (this.speed.x * this.collisionX > 0) {
        this.speed.x = 0;
    }
    
    // this.prePosition.x = this.node.x;
    // this.prePosition.y = this.node.y;

    // this.preStep.x = this.speed.x * dt;
    // this.preStep.y = this.speed.y * dt;
    
    this.heromotion.x=this.node.x += this.speed.x * dt;
    this.heromotion.y=this.node.y += this.speed.y * dt;

    for (var i = 0; i <this.monstersS.length; i++)
    {
        if(this.node.y < this.monstersY[i]+20 &&  this.node.y > this.monstersY[i]-20 ){

           if(this.monstersC[i].canAttack){

            var MBP=cc.instantiate(this.monsterBulletP);

            MBP.parent  = this.monstersS[i].node;

            this.monstersC[i].canAttack = false;

            var monsterc = this.monstersC[i];
            
            setTimeout(function() {

                monsterc.canAttack = true;
            
            }, 1000);
           
            break;
           }
        }

        

     

        
    }



},

});

不好意思啊,问题已经解决,是我的代码有问题。不过在浏览器运行的确是不会有问题的,不知道为什么啊,不过没事了