Jump to content

bitmapText anchor is undefined....?


espace
 Share

Recommended Posts

hi,

i try to use the bitmap text...no problem (my text appears)

When i type the e.player.anchor.x=0.5; i have an error.

What do i wrong ? i have put the font and the the font.png and font.fnt below....

i have follow this :

http://phaser.io/examples/v2/text/bitmaptext-anchor-y

thanks if you have a solution.

 

//preload.js
var preload = function(game){}

preload.prototype = {
	preload: function(){ 
		this.game.load.bitmapFont('lucky','assets/font.png', 'assets/font.fnt');

	},
  	create: function(){
		this.game.state.start("GameTitle");
	}
}


//hud.js
function drawText(game){
	var e=[]
	e.player = game.add.bitmapText(w4*3,20+20,'lucky','JOJO', w*.1);
	e.player.anchor.x = 0.5;
	e.player.anchor.y = 0.5;
	return e;
}
//in my thegame.js
//
drawText(game)

//error is : TypeError: e.player.anchor is undefined

 

LuckiestGuy.ttf

font.fnt

font.png

Link to comment
Share on other sites

It looks like drawText is getting called before your game has started. What about putting the call to drawText in your preload state's create function?

Also, this confuses me:

var e=[]
e.player = game.add.bitmapText(w4*3,20+20,'lucky','JOJO', w*.1);
e.player.anchor.x = 0.5;
e.player.anchor.y = 0.5;
return e;

I think you meant "var e = {};" instead of "var e = []". [] means you're making an array, {} means you're making an object. But why make an object that holds your player and then return it? Why not just make the player and return that directly? What are you trying to do?

Link to comment
Share on other sites

Hi Drhayes :)

Drawtext is called in "thegame.js" not in preload, i have put comments.

I have also simplified my snippet for the forum and i have for example e.opponent, e.score etc...so i need to put an array.

I have found a discussion about a problem with anchor in 2014 with Rich (the administrator) and i see the pseudo soluce here : 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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