Collision of frames P2

旧街凉风 提交于 2019-12-12 02:34:29

问题


I'm trying to determine the points of the players based on the different frame that a bullet hits, is this possible? So basically I want to for example, give 100 points if figurapega matches figura, and 50 points if it does not, but I have not been please my code below.

///////Here I load the atlas
this.load.atlas('Monsters', 'asset/game1/Monstruos/monstruos.png', 'asset/game1/Monstruos/monstruos.json');

///this is the one I want to use as reference to compare

        createFiguraCompare: function(){
        
                //Figura para comparar
        this.figuritaspega = this.game.add.sprite(800, 140, 'Monsters', this.rnd.integerInRange(0,4));
        this.figuritaspega.scale.set(0.5, 0.5 );
        
        
    },

/////////and this is the one generating sprites that need to be shot at

    
        makeOneFigura: function() {
          
        this.figura = this.game.add.group();
        this.figura.enableBody = true;    
        this.figura.physicsBodyType = Phaser.Physics.P2JS;
    //         for (var i = 0; i < 5; i++){
        this.figura.createMultiple(100, 'Monsters', 0, false);  
    //         }
        this.figura.setAll('anchor.x', 0.5);
        this.figura.setAll('anchor.y', 0.5);
        this.figura.setAll('outOfBoundsKill', true);
        this.figura.setAll('checkWorldBounds', true); 


        
        
        
    },
    
      makeFiguras: function(x, y){ 

   if (this.timerFiguras) {
            this.figuras = this.figura.getFirstExists(false);
       if (this.figuras) {
            this.figuras.reset(0, 350);
             this.figuras.frame = this.game.rnd.integerInRange(0,4);  
             this.figuras.body.setCollisionGroup(this.figuraCG);
            this.figuras.body.collides(this.bulletCG); 
            this.figuras.body.velocity.x = 1000;
        }
   };

    },



/////and last but no least the collision handler which is where Im trying to compare but with no luck

    
        collisionBulletFigura: function(bullet, figuras, score, scoreText, figuritaspega) {
        
            if (this.figuras.frame === this.figuritaspega.frame){
       figuras.sprite.kill();
        bullet.sprite.kill();
            this.score += 100;
            this.scoreText.text = this.score;
       }else {
                  figuras.sprite.kill();
        bullet.sprite.kill()
        
         this.score += 50;
            this.scoreText.text = this.score;
       }

            
        
    },

来源:https://stackoverflow.com/questions/39732414/collision-of-frames-p2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!