Hi all,
I am new in making game, I am making ‘match game’ using phaser.
I have a problem when trying to make collision between ‘cigarette card’ and ‘dubai tower’ that rotate to the globe…
I want to make the ‘cigarette card’ fall to the y direction when I click pointer. If the cigarette card match with the ‘dubai tower’, the ‘dubai tower’ is going to change to ‘destroyed image’ that have been loaded
here my codes
var config = {
type: Phaser.AUTO, width: 700, height: 1000, backgroundColor: '0x444444', parent: 'phaser-example', scene: { preload: preload, create: create }, physics: { default: 'arcade', arcade: { debug: false, } }
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.image("bg", "assets/background.jpg"); this.load.image("dubaiitem", "assets/dubai.png"); this.load.image("nyitem", "assets/new-york.png"); this.load.image("taipeiitem", "assets/taipei.png"); this.load.image("parisitem", "assets/paris.png"); this.load.image("target", "assets/globe.png"); this.load.image("dubai", "assets/extra-menthol-dubai.png"); this.load.image("paris", "assets/chill-menthol-paris.png"); this.load.image("ny", "assets/fast-forward-purple-new-york.png"); this.load.image("taipei", "assets/fast-forward-taipei.png"); this.load.image("destroyed", "assets/splatter.png")
}
var container;
var target;
var destroyed;
var dubai;
var dubaiitem;
var ny;
var nyitem;
var taipei;
var taipeiitem;
var paris;
var parisitem;
var dubai2;
var dubaiitem2;
var ny2;
var nyitem2;
var taipei2;
var taipeiitem2;
var paris2;
var parisitem2;
function create ()
{
//background this.add.image(350,500,'bg') //sprite globe container = this.add.container(game.config.width/2, 1080); target = this.add.sprite(0, 0, 'target'); dubaiitem = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(0,0) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(0,0) - 90)), "dubaiitem" ) dubaiitem.setScale(1.5); dubaiitem.setAngle(0); dubaiitem.setOrigin(0.5,-0.05) nyitem = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(45,45) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(45,45) - 90)), "nyitem" ) nyitem.setScale(1.5); nyitem.setAngle(45); nyitem.setOrigin(0.5,-0.05) taipeiitem = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(90,90) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(90,90) - 90)), "taipeiitem" ) taipeiitem.setScale(1.5); taipeiitem.setAngle(90); taipeiitem.setOrigin(0.5,-0.05); parisitem = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(135,135) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(135,135) - 90)), "parisitem" ) parisitem.setScale(1.5); parisitem.setAngle(135); parisitem.setOrigin(0.5,-0.05); dubaiitem2 = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(180,180) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(180,180) - 90)), "dubaiitem" ) dubaiitem2.setScale(1.5); dubaiitem2.setAngle(180); dubaiitem2.setOrigin(0.5,-0.05) nyitem2 = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(225,225) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(225,225) - 90)), "nyitem" ) nyitem2.setScale(1.5); nyitem2.setAngle(225); nyitem2.setOrigin(0.5,-0.05) taipeiitem2 = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(270,270) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(270,270) - 90)), "taipeiitem" ) taipeiitem2.setScale(1.5); taipeiitem2.setAngle(270); taipeiitem2.setOrigin(0.5,-0.05); parisitem2 = this.add.sprite(target.x + (target.width / 2) * Math.cos(Phaser.Math.DegToRad( Phaser.Math.Between(315,315) - 90)), target.y + (target.width /2) * Math.sin(Phaser.Math.DegToRad( Phaser.Math.Between(315,315) - 90)), "parisitem" ) parisitem2.setScale(1.5); parisitem2.setAngle(315); parisitem2.setOrigin(0.5,-0.05); container.add(target); container.add(dubaiitem); container.add(nyitem); container.add(taipeiitem); container.add(parisitem); container.add(dubaiitem2); container.add(nyitem2); container.add(taipeiitem2); container.add(parisitem2); this.tweens.add({ targets: container, angle: 360, duration: 6000, repeat: -1, }); //sprite cards dubai = this.add.sprite(700,200, 'dubai').setInteractive(); this.tweens.add({ targets: dubai, x: 10, duration: 3500, repeat: -1, yoyo: true }); this.input.on('pointerdown', function (pointer) { this.tweens.add({ targets: dubai, y: { value: 3000, duration: 1000} }); //collision this.physics.add.existing(dubai) this.physics.add.existing(dubaiitem) console.log(dubai) console.log(dubaiitem) this.physics.add.collider(dubai, dubaiitem) }, this);
}
function update()
{
}