Jump to content

Set anchor property to dynamically added text in Phaser


kstamatov85
 Share

Recommended Posts

Hi guys, I have a problem with setting the anchor position of text object that have no refference for.

var profileData = this.add.group();for(x in GH.userProfileData){  profileData.add(this.game.make.text(0, pos, GH.lang.userProfileLabel[x]+': ', GH.font.labelFont));  profileData.add(this.game.make.text(200, pos, GH.userProfileData[x].toString(), GH.font.valueFont));  pos+=50;		}

I try chaining .anchor(1,0) to first text, but it did not work and unfortunately couldn't  found anything about that issue.

Anybody know how to solve that issue?

Link to comment
Share on other sites

I try that, because it was most obvious, but phaser returns "TypeError: a.setStageReference is not a function".

Anyway I found a workaround, but it is not as elegant as I would like to be.

var textObj = {};for(x in GH.userProfileData){  textObj.x = this.add.text(200, pos, GH.lang.userProfileLabel[x]+': ', GH.font.labelFont);  textObj.x.anchor.setTo(1, 0);			};

I guess there should be a phaser way to do that more clean

Link to comment
Share on other sites

anchor is not function - it is object. This is reason, why you got error when calling it like "anchor()" with parenthesis. It is Phaser.Point object, that has x and y ... and you can change it like: .anchor.x = ... or both at once like anchor.set(x, y) or anchor.setTo(x, y).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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