Jump to content

Sinking effect and image click


kray
 Share

Recommended Posts

I have a phaser game. My aim now is to make the group 'question' appear to sink in the sea. If the user clicks on the correct option, the ship should come back up. If the user clicks on the wrong option, the ship should sink completely.

 

The JS:

 

create: function() {    game.physics.startSystem(Phaser.Physics.ARCADE);        this.bgMusic = this.game.add.audio('bgMusic');    this.bgMusic.loop = true;    this.bgMusic.play();        //background    this.background = this.game.add.sprite(0,0,'bg');    this.sea = this.game.add.sprite(0,0,'sea');    //this.ship = this.game.add.sprite(this.game.world.centerX,340,'ship');    question = this.game.add.group();        var ship = question.create(this.game.world.centerX,340,'ship');    ship.anchor.setTo(0.5);    var text = question.create(this.game.world.centerX,420, 'question');    text.anchor.setTo(0.5);        this.seafg = this.game.add.sprite(0,400,'seafg');        this.hasB = this.game.add.sprite(30, 40, 'has');    this.hasB.inputEnabled = true;    this.hasB.events.onInputDown.add(this.answer,this);    this.haveB = this.game.add.sprite(150,40,'have');    this.haveB.inputEnabled = true;    this.haveB.events.onInputDown.add(this.answer,this);    this.amhasB = this.game.add.sprite(270,40,'amhas');    this.amhasB.inputEnabled = true;    this.amhasB.events.onInputDown.add(this.answer,this);    this.ishavingB = this.game.add.sprite(390,40,'ishaving');    this.ishavingB.inputEnabled = true;    this.ishavingB.events.onInputDown.add(this.answer,this);}

In the update function, I tried

question.body.velocity.y=-5;

But this stopped rendering the game. I also added constructs to check which sprite is being clicked in the function 'answer', but that too stopped the game from rendering. How do I achieve what I want?

 

post-13815-0-95961700-1427366181.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...