Jump to content

attaching a text with sprite image and making the text able to tween with sprite image


Manikant tiwari
 Share

Recommended Posts

I am very new to phaser. I am creating a game with phaser 2.x. I want to apply tween on text along with the sprite which is parent of the text, because I have made text as a child of the sprite image.

I have tried with the following code.

var GameState = {
  preload:function(){
        ---------
        this.load.image('blackboard', 'assets/images/ticket2.jpg')
        this.load.image('arrow', 'assets/images/arrow.png')
        ---------
  }
  create:function(){
    ------
        this.blackboard = this.add.sprite(this.game.world.centerX, 525, 'blackboard');
        this.blackboard.anchor.setTo(0.5)

        this.arrow = this.add.sprite(40, 370, 'arrow')
        this.arrow.anchor.setTo(0.5)
        this.arrow.inputEnabled = true;
        this.arrow.events.onInputDown.add(this.showBlackboard, this)
    ------
  },
  showBlackboard: function () {
        var whiteStyle1 = { font: "25px Arial", fill: "#ffffff" }
        this.one = this.add.text(120,280,"1",whiteStyle1);
        this.blackboard.addChild(this.one);
        var tween = this.add.tween(this.blackboard);
        tween.to({ y: 350 }, 500)
        tween.start();
  }
}

Only the blackboard is being tweened. Even the text is not being printed on the screen. Can anybody give me a solution please

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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