razorsese Posted December 22, 2014 Share Posted December 22, 2014 I'm creating 6 circles and i want to draw on each of them a text right in the center but so far it is slightly offset from centerwindow.onload = function () { var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render}); var circles; var pos_x = [100,250,320,376,420,448]; var pos_y = [78,150,220,276,320,389]; function create_circles(){ for(var i=1;i<=6;i++){ var circle = game.add.sprite(pos_x[i], pos_y[i],"CIRCLE"); circle.tint = 0xFF20A0; circle.scale.set(0.5,0.5); circle.inputEnabled = true; var style = { font: "10px Arial", fill: "#FFFFFF", wordWrap: true, wordWrapWidth: circle.width, align: "center" }; circle.events.onInputDown.add(listener , this); text = game.add.text(pos_x[i], pos_y[i], "10", style); text.anchor.set(-1); } } function preload() { this.game.load.image('CIRCLE', 'circle.png'); } function create() { game.stage.backgroundColor = '#FFFFFF'; create_circles(); } function update() { } function render () { } function listener(sprite, pointer){ sprite.alpha = 0.5; }}; Link to comment Share on other sites More sharing options...
shmikucis Posted December 22, 2014 Share Posted December 22, 2014 I would find center point of circle and add text anchor point right in the middletext = game.add.text(pos_x[i]+circle.width/2, pos_y[i]+circle.height/2, "10", style);text.anchor.setTo(0.5, 0.5); Link to comment Share on other sites More sharing options...
Recommended Posts