2015-08-19 103 views
1

我試圖做一個匹配遊戲,你有4個精靈,其中3個有他們的東西,另一個精靈有像anwnser例如問題可能是分數和小數的匹配和你會有3個小數或3位小數,其中一個oposite作爲正確的awnser在另一個sprite上,你匹配正確的一個。但我的問題是,我不能讓精靈來詆譭他們正在碰撞。這是我到目前爲止。Phaser.js拖放問題

/* 
* 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

創建功能啓用S1game.physics.arcade.enable(s1); game.physics.arcade.overlap(cone,s1,collisionHandler,null,this);物理學在更新功能的乞討做吧。你也可以使用game.physics.arcade.collide(//你的params);

這裏有些鏈接可能會有所幫助 - detect collision and overlap

overlap with a scaled sprite

+0

好的,謝謝還我怎麼能夠切換水平,因爲有沒有真正瞭解如何切換和添加水平的任何好TUTS。 – Sabre

+0

您可以通過在Phaser中使用* state *來切換關卡首先添加game.state.add(「BossLevel」,bossLevel);然後開始狀態game.state.start('BossLevel');您可以在Phaser主頁的示例部分中找到更多關於此的信息。 –

+0

這裏的教程不是很好,對我來說有點難理解,遊戲狀態部分。 – Sabre