Jump to content

Sprite Index and Change Text of BitmapText


turnA
 Share

Recommended Posts

Hi there,

 

Want to ask some (maybe) simple things from Phaser:

1. How to change a sprite placement index? I want to swap the image and place them in different order, not just get them to the top (like in input example).

2. How do I update the text of BitmapText? My code is:

this.time = 59;this.timeTxt = this.game.add.bitmapText(58, 934, '60', { font: '60px bradbun', align: 'left' });this.timeTxt.anchor.setTo(0.5,1);this.timeTxt.setText(""+this.time);

But it seem not working for me.

Any help is appreciated.

 

Thanks!

Link to comment
Share on other sites

2. How do I update the text of BitmapText? My code is:

this.time = 59;this.timeTxt = this.game.add.bitmapText(58, 934, '60', { font: '60px bradbun', align: 'left' });this.timeTxt.anchor.setTo(0.5,1);this.timeTxt.setText(""+this.time);

 

 

2) setText is correct. Have confirmed this working in 1.0.7-beta, but should be ok in 1.0.6 too hopefully?

I'm using Phaser 1.0.6 and setText works perfectly. turnA, you should also place setText in the update function, not just in the create function.

Link to comment
Share on other sites

1)  World has a default Group (world.group) which has a 'swap' function. Use that to exchange the places of 2 children.

 

2) setText is correct. Have confirmed this working in 1.0.7-beta, but should be ok in 1.0.6 too hopefully?

 

Thanks for the info, works like charm! So I guess we can't use number for sprite index placement (aka addChildAt/setChildIndex like in Flash)?

Can't wait for the documentation soon.

 

I'm using Phaser 1.0.6 and setText works perfectly. turnA, you should also place setText in the update function, not just in the create function.

 

That's exactly what happen! Thanks scutajar! :D

Link to comment
Share on other sites

Thanks for the info, works like charm! So I guess we can't use number for sprite index placement (aka addChildAt/setChildIndex like in Flash)?

Can't wait for the documentation soon.

 

 

That's exactly what happen! Thanks scutajar! :D

 

You can addAt() in a Group, yes. You can also getIndex(child) which you can use with addAt(), but there is no "setChildIndex".

Link to comment
Share on other sites

  • 3 months later...

I thought I had an issue with the bitmapText sitting behind other layers and spent ages trying to swap layers etc, but realised that I was passing a number to the 'setText' function and it does not display anything if you do this.

 

Lesson learnt - Convert Numbers to Strings when passing to the text field.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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