Phaser.js拖放问题

时间:2015-08-19 19:27:47

标签: javascript phaser-framework

我正在尝试制作一个匹配的游戏,你有4个精灵,其中3个有一些东西,另一个精灵就像anwnser,例如问题可能是分数和小数的匹配,你会有3个分数或3个小数与其中一个oposite作为正确的awnser在另一个精灵上,你匹配正确的。但我的问题是我不能让精灵欺骗他们正在相撞。这是我到目前为止所做的。

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {preload: preload, create: create, update: update});

function preload() {
    game.load.image('Cone','pics/ICE-Cream-cone_1.png');
    game.load.image('back','pics/BakerIceBackground_1.png');
    game.load.image('Shoot','pics/CreamShoot.png');
    game.load.image('star','pics/star.png');
}

var cone;
var text;

function create() {    
    back = game.add.sprite(0, 0, 'back');
    s1 = game.add.sprite(500, 250, 'Shoot');
    s2 = game.add.sprite(280, 250, 'Shoot');
    s3 = game.add.sprite(60, 250, 'Shoot');
    cone = game.add.sprite(300, 400, 'Cone');
    cone.inputEnabled = true;
    cone.input.enableDrag();

    game.physics.enable(cone, Phaser.Physics.ARCADE);

    var style = {font: "32px comic sans", fill :"#ff0044", wordwrap: true, wordWrapWidth: cone.width,align:"center"};
    text = game.add.text(0,0, "test", style);
    text.anchor.set(0.5);
}

function update() {       
    text.x = Math.floor(cone.x + cone.width / 2);
    text.y = Math.floor(cone.y + cone.height / 2);
    game.physics.arcade.overlap(cone,s1,collisionHandler,null,this);
    //CX = s2.x;
    //CY = s2.y;
    // console.log(CY);
    // console.log(CX);

    function collisionHandler() {
        console.log("game Over");
    }   
}

1 个答案:

答案 0 :(得分:1)

创建函数中的

启用 s1的物理 game.physics.arcade.enable(s1); game.physics.arcade.overlap(cone,s1,collisionHandler,null,this);更新功能的乞讨时执行此操作。你也可以使用 game.physics.arcade.collide(//你的参数);

此处某些链接可能会有所帮助 - detect collision and overlap

overlap with a scaled sprite