LibGDX - Particle Effect Fade Out - libgdx

So I have particle effect(with additive: false) and now I want to create beautiful fade out effect. I've tried to make something like that:
Color color = batch.getColor();
batch.setColor(color.r, color.g, color.b, color.a * alpha);
but it doesn't work for particle effect.
Does anyone know how to change alpha of particle effect?

Solution was pretty simple :D
All You need is:
m_particleEffect.getEmitters().get(0).getTransparency().setHigh(0.5f/*alpha*/);
Hope this will help someone :)

If you look at the ParticleEmitter.draw code, you'll see the blend mode of the drawing is controlled by the setAdditive (which you say you have set to false) and setPremultipliedAlpha methods. It looks like you want to use pre-multiplied alpha, but I'm unsure of how the batch color interacts with the texture color in LibGDX. Try setting pre-multiplied alpha to true first.

Related

LibGDX BitmapFont Markup Alpha Value

Alright, so I have a bitmap font with markup enabled. The problem is, I need to set the global alpha value for a whole string of text without setting an individual alpha value for each color code.
For example, I have...
"[#0000ff]this is blue, [#990000]this is red"
I'd like the font text to fade into the background by setting an alpha value. Is there any way to do this without manually parsing color codes and sticking an alpha value into the brackets?
I've also tried adding custom colors with Colors.put(..), but that gets really clunky, as I have to set the alpha value to each color I'm using, with each line of text that I am drawing.
You'll need to use the BitmapFontCache class.
So for example, say your code currently looks like this...
font.drawWrapped(batch, text, x, y, wrapWidth, alignment);
Replace it with the following and you can control the alpha in the way you require...
BitmapFontCache cache = font.getCache();
cache.clear();
TextBounds bounds = cache.addMultiLineText(text, x, y, wrapWidth, alignment);
// This is the useful bit!
cache.setAlphas(alphaTransparency);
cache.draw(batch);
Note - If you're using distance field fonts then the shader most people use for them doesn't support alpha, but it's easy to fix it so it does. Let me know if you hit that problem.

Flash color transform

I'm having difficulty with transforming colour in Flash. It should be easy I think, but for some reason my code isn't working as expected.
I have a bitmap graphic consisting of a colour spectrum from red to yellow to green (you know, like you see in an audio level meter).
I simply want to sample a colour from that bitmap and then tint a movie clip on stage that sampled colour. (the effect I'll be going for is coloured progress - the closer you get to 100% green is displayed, the closer you are to 0% it's red - I haven't implemented that part yet, but I'm not worried about that).
Anyhow, I sample the colour just fine, and tint my clip, but no matter what I tint the clip it comes up a different colour than what I've sampled (the trace is a different colour than what I see on the clip). I can't see where I'm going wrong - I'm hoping it's a stupid mistake and someone can spot it easily.
import flash.display.BitmapData;
var bmd:BitmapData = new BitmapData(mc_colourbar.width, mc_colourbar.height);
bmd.draw(mc_colourbar);
var pixelvalue:uint = bmd.getPixel(0, 1);
trace(pixelvalue.toString(16));
var colourtransform:ColorTransform = mc_box.transform.colorTransform;
colourtransform.color = uint("0xff" + pixelvalue);
mc_box.transform.colorTransform = colourtransform ;
mc_box is the clip on stage I'm trying to tint - it's simply a white square.
Any help is appreciated, thanks in advance!
ColorTransform.color expects an RGB value, and it appears as though you're attempting to give it an ARGB value*.
Change the line:
colourtransform.color = uint("0xff" + pixelvalue);
to just:
colourtransform.color = pixelvalue;
and your code should work as expected.
*Though I don't think the way you're trying to do it here is correct.

Is it possible to adjust contrast of ccsprite in cocos2d-x?

I'm trying to give ccsprite blink effect by adjusting brightness.
so I need to adjust contrast of ccsprite.
How to do that?
CCSprite* ccs_sprite = CCSprite::create("button.png");
ccs_sprite->setPosition(ccp(500, 500));
ccs_sprite->setContrast()???
addChild(ccs_sprite);
You can get a blink effect by adjusting the opacity of the sprite with the setOpacity method and alternatively using the CCFadeIn, CCFadeOut and CCFadeTo actions.
Edit:
There is also the CCTintTo and CCTintBy actions that will adjust the RGB colors of the node.
You can visit here for detail reference about classes in cocos2d-x
http://www.cocos2d-x.org/reference/native-cpp/V2.2/d4/de7/classcocos2d_1_1_c_c_sprite.html

Apply BOTH BlendMode AND filter to same movieClip?

Im trying to create a 'neon glow effect thru a combination of both BlendModes and glow filter
Problem is, they seem to cancel each other out if applied together...not having any luch doing this dynamically.
Can anyone help?
You could try something like:
Apply BlendMode to your graphic
Use BitmapData, and draw() your graphic so you get a new bitmap representation of it (pretty much what applying a blendmode or a filter will do anyway)
Apply your Filter to this new Bitmap
???
Profit

as3: draw circle with a hole in it using only actionscript

Okay so basically I want to draw a circle in as3 that has a 'hole' in it (like a donut). Something like this, but without the outlines:
http://www.steel.ie/DugganSteel/Pictures/Hollow-circle.gif
This doesn't work:
SPRITE.graphics.beginFill(0xFFFFFF);
SPRITE.graphics.drawCircle(0,0,10);
SPRITE.graphics.endFill();
SPRITE.graphics.drawCircle(0,0,5);
I mean this seems like it'd be simple but I can't find any information on it. I should also mention that I'm trying to only draw 3/4 of the circle, like 3/4 of donut. So I was planning on drawing a transparent circle and square over the original circle, I know this seems kinda of weird since you'd expect something transparent to show whats underneath it.
Its actually really simple. See the following code:
var p:Point = new Point(100, 100);
graphics.beginFill(0xFF0000);
graphics.drawCircle(p.x, p.y, 100);
graphics.drawCircle(p.x, p.y, 50);
Intersections cancel each other out until you call endFill
Goodluck!
You can just make the line thickness the desired donut width and avoid using beginFill
set graphics.lineStyle
To make it only go 3/4 of the way around you could use curveTo to draw the 3 quarters.
The above method by Tyler works, however if an easier way to do it is to simply begin drawing the inner circle first. Basically Flash doesn't actually fill in the color until you call endFill() (again as mentioned by Tyler), so you start drawing on the inner circle, then the outer circle then on endFill() Flash fills in the gap.
SPRITE.graphics.beginFill(0xFFFFFF);
SPRITE.graphics.drawCircle(0,0,5);
SPRITE.graphics.drawCircle(0,0,10);
SPRITE.graphics.endFill();
Hope this clears things up for you.
Introduction to Flash drawing API, will help you understand a bit more :
http://www.senocular.com/flash/tutorials/flash10drawingapi/