Jump to content

Displaying Text on top of a Sprite


Philkin
 Share

Recommended Posts

Hello!

 

I am attempting to display text on top of my 'cloud' sprites as the float across the sky.

 

I am making use of the addChild() method, rather than grouping just because grouping produces strange results.

 

The text is successfully added to the sprite as a child, however it is not being displayed; help?

 

		clouds[cloudIndex] = new Cloud(game, cloudXML.getElementsByTagName("type")[Zadi].childNodes[0].nodeValue, cloudXML.getElementsByTagName("text")[Zadi].childNodes[0].nodeValue);		//clouds[cloudIndex].z = -1;		cloudText[cloudIndex] = game.add.text(clouds[cloudIndex].x, clouds[cloudIndex].y, clouds[cloudIndex].txt, {fontSize: '12px', fill: '#000'});		//cloudText[cloudIndex].z = 1;		clouds[cloudIndex].addChild(cloudText[cloudIndex]);		console.log(clouds[cloudIndex].children);		// game.add.sprite((Math.random() * (1000-900) + 900), (Math.random() * (600-200)), 'cloud1');		clouds[cloudIndex].anchor.x = 0.5;		clouds[cloudIndex].anchor.y = 0.5;		//Create tween and add to cloud object		var twCloud = game.add.tween(clouds[cloudIndex]);		twCloud.to({x: -100}, (Math.random() * (7500 - 5000) + (5000)));		twCloud.start();

All help is much appreciated!

P

Link to comment
Share on other sites

Nevermind!

I am an idiot - addChild adds the child relative to the x, y coordinates of the parent!

 

		clouds[cloudIndex] = new Cloud(game, cloudXML.getElementsByTagName("type")[Zadi].childNodes[0].nodeValue, cloudXML.getElementsByTagName("text")[Zadi].childNodes[0].nodeValue);		//clouds[cloudIndex].z = -1;		cloudText[cloudIndex] = game.add.text(0, 0, clouds[cloudIndex].txt, {fontSize: '6px', fill: '#000'});		//cloudText[cloudIndex].z = 1;		cloudText[cloudIndex].z = 0;		clouds[cloudIndex].addChildAt(cloudText[cloudIndex], 0);		console.log(clouds[cloudIndex].z);		console.log(clouds[cloudIndex].getChildAt(0).z);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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