Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have this

batch.draw(currentFrame, x, y, this.parent.originX, this.parent.originY, this.parent.width, this.parent.height, this.scaleX, this.scaleY,this.rotation);

I want to apply the alpha that it gets from the method, but theres is not overload from the SpriteBatch class that takes the alpha value, is there some wey to apply it? (i did it this way, because this are animation, and i wanted to control them) in my static ones i apply

sprite.draw(SpriteBatch, alpha)

Thanks

share|improve this question

2 Answers 2

There isn't a built-in way of doing this, but you can do it by temporarily modifying the Color which SpriteBatch blends your texture with; usually used for tinting though. This is untested, but it should work...Let me know if it does.

Color color = batch.getColor();//get current Color, you can't modify directly
float oldAlpha = color.a; //save its alpha

//From here you can modify alpha however you want
float scale = 0.5;
color.a = oldAlpha*scale; //ex. scale = 0.5 will make alpha halved
setColor(color); //set it
batch.draw(currentFrame, x, y, this.parent.originX, this.parent.originY, this.parent.width, this.parent.height, this.scaleX, this.scaleY,this.rotation);

//Set it back to orginial alpha when you're done with your alpha manipulation
color.a = oldAlpha;
setColor(color);

This is actually similar to what sprite.draw(SpriteBatch, alpha) do if you look at source.

share|improve this answer

Another way could be to use Sprites instead of TextureRegion for the Animation (you have to cast the TextureRegion probably) since Sprite has color field which uses when using it with the SpriteBatch. However, if you change to use Sprites you need to know you have to call sprite.render(spriteBatch) and no the inverse way.

Btw, if the previous answer by XiaoChuan Yu was useful remember to mark your question as answered so it is removed from unanswered questions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.