phaser-input icon indicating copy to clipboard operation
phaser-input copied to clipboard

Using Phaser Anchor set

Open mdere opened this issue 8 years ago • 5 comments

It seems like when I use input_field_object.anchor.setTo(0.5) and it seems like does anchor the input field to center, but the input itself is out of aligned.

Is this expected behavior?

image

Reason I am doing this way because I want the center of the input field to be absolute based on game.word.centerX, if do that without anchor - it seems like the left of the input box is where the start of the x and y coords begin.

mdere avatar Feb 11 '17 20:02 mdere

Would you care to give us a small code snipped of the problem causing code? We tried to recreate it and the only way it's reappearing is when we hard set the x position of the text. The alignment of the input box should all be handled correctly by the plugin and no manual positioning should be needed.

DavidZwit avatar Feb 13 '17 12:02 DavidZwit

@DavidZwit - hm I pretty much gave up and just did relative position - all I remember was that the anchor.set on that input object screws up the input box

have you tried to anchor it to (0.5)?

mdere avatar Feb 20 '17 18:02 mdere

I'm having this exact issue. My code is very simple:

export default class Menu extends Phaser.State {
	public game: PhaserInput.InputFieldGame;

	private nameInput: PhaserInput.InputField;

	public create() {
		this.nameInput = this.game.add.inputField(this.game.width / 2, this.game.height / 2, {
			font: '50px Arial',
			fill: '#212121',
			fontWeight: 'bold',
			width: 600,
			padding: 8,
			borderWidth: 1,
			borderColor: '#000',
			borderRadius: 6,
			placeHolder: 'Name',
			textAlign: 'center'
		});

		this.nameInput.anchor.setTo(0.5, 0.5);
	}
}

The rest of my setup is detailed in issue https://github.com/orange-games/phaser-input/issues/53

tommitytom avatar Jul 18 '17 03:07 tommitytom

#56

ghandhikus avatar Sep 12 '17 14:09 ghandhikus

there is need to add options for horizontal and vertical textAlign, so if textbox has none default height textAlign: center doesn't work properly for height alignment

RollinSafary avatar Nov 06 '17 10:11 RollinSafary