stone Posted May 28, 2014 Share Posted May 28, 2014 Why not centered on the sprite??????var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, 'game_div'); var scale = window.innerHeight/9; var main_state = { preload: function() { game.load.image('hello', 'assets/bird1.png'); }, create: function() { this.hello = this.game.add.sprite(20, 20, 'hello'); this.hello.width = this.hello.height = scale; var text = game.add.text(0, 0, '10', {font: parseInt(scale/2)+'px arial', fill: '#aaa'}); this.hello.addChild(text); text.position.x = (scale - text.width)/2; text.position.y = (scale - text.height)/2; }, update: function() { } }; game.state.add('main', main_state); game.state.start('main'); Link to comment Share on other sites More sharing options...
Pedro Alpera Posted May 28, 2014 Share Posted May 28, 2014 Look this example: http://examples.phaser.io/_site/view_full.html?d=basics&f=06+-+render+text.js&t=06%20-%20render%20text&jsbin=http://jsbin.com/zagob/11/edit?js,output Link to comment Share on other sites More sharing options...
haden Posted May 28, 2014 Share Posted May 28, 2014 Because you didn't took the sprite position when centering the text. Your code should be more like this:text.position.x = hello.x + (scale - text.width)/2;text.position.y = hello.y + (scale - text.height)/2; Link to comment Share on other sites More sharing options...
stone Posted May 28, 2014 Author Share Posted May 28, 2014 @haden this.hello.addChild(text); the line of code enables text to be located relative to this.hello, and it's no need to add hello coordinate. Link to comment Share on other sites More sharing options...
stone Posted June 6, 2014 Author Share Posted June 6, 2014 Anyone knows how to solve this problem? Link to comment Share on other sites More sharing options...
Recommended Posts