Jump to content

Text particles?


Wolfsbane
 Share

Recommended Posts

Hi Team,

I can't quite figure out if it's possible to have a Text object as the particle texture?

var partText = new game.Text('Perfect!');
            partText.setFont("Riffic_Black");
            partText.anchorCenter();
            partText.scale.set(1.7);
            //partText.addTo(game.scene.stage);
            
            var particles = new game.Particles();
            particles.textures.push(partText);
            particles.emitDuration = 30;
            particles.emitRate = 2;
            particles.emitCount = 1;
            particles.angle = 4.8;
            particles.speed = 300;
            particles.life = 400;
            particles.rotate = 0;
            particles.rotateVar = 1;
            particles.lifeVar = 100;
    	    particles.startPos.set(game.width / 2, game.height / 3);
            particles.angleVar = 0.2;
    	    particles.speedVar = 30;
    	    particles.addTo(this.stage);  

 

This, doesn't work. (It wants a Sprite, not a Text in particles.textures.push(x);

I had a quick look through Text, and Container classes.. it's going to take me a while to run through it, as nothing is obviously popping out as 'here's the texture'. :)

Has anyone done this before? If yes, then you'll save me an hour or so of debugging...!

Link to comment
Share on other sites

Hi Team,

Found some time to look into this. You can do this by turning cache on for the Text, and then using the texture of the cache'd sprite.

E.g.

var text = new game.Text('Hello Panda');
text.cache = true;
//text._generateCachedSprite();
        
        
//Particle test.
var particles = new game.Particles();
particles.textures.push(text._cachedSprite.texture);
particles.position.set(game.width / 2, game.height / 2);
particles.addTo(this.stage);

 

And looks pretty good, too. :)

image.png.2378c753e19d42ac328adf8274f9841a.png

 

This is still not a clean way, as you have to use the _cachedSprite.texture, which you kind of want to think of as hidden variables. I'm also not sure if it's necessary to turn caching on for the text.

I tried playing around with the source, and did something like this:

//Text.js -> add new method to getTexture
getTexture: function() {
		this._generateCachedSprite();
		return this._cachedSprite.texture;
	},



//Particle code in Main.js is now:
var text = new game.Text('Hello Panda');

var particles = new game.Particles();
particles.textures.push(text.getTexture());
particles.position.set(game.width / 2, game.height / 2);
particles.addTo(this.stage);

 

I something like this should be a bit cleaner. And I think it's kind of useful to be able to just pull out the Texture like this. @enpu

Useful, or nah?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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