Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 9:12 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Animation and alpha
PostPosted: Wed Jul 04, 2012 8:47 am 
Offline

Joined: Mon Sep 12, 2011 9:07 am
Posts: 14
I everybody,

I'm trying to draw an animation with an alpha value but it doesn't work... The image still render without alpha !

Here is my code :
Code:
public class SimpleAnimation extends Animation {
   public static final int FRAME_TIME = 100;
   
   private SpriteSheet sheet;
   
   public SimpleAnimation(SpriteSheet sheet, int nbrFrames) {
      this.sheet = sheet;
      init(nbrFrames);
   }
   
   private void init(int nbrFrames) {
      for (int i = 0; i < nbrFrames; i++) {
         addFrame(sheet.getSprite(i, 0), FRAME_TIME);
      }
      setAutoUpdate(false);
   }
   
   public void reset() {
      setCurrentFrame(0);
   }
   
   public void setAlpha(float alpha) {
      sheet.setAlpha(alpha);
   }
}


And i do this :
Code:
SimpleAnimation animation = new SimpleAnimation(sheet, 8);
animation.setAlpha(0.75f);
[...]
// On the render method
animation.draw(vector.getX(), vector.getY());


Can anybody explain to me what's wrong ?

Thanks a lot.

_________________
If you search on google, you find forums where users tell you to search on google...


Top
 Profile  
 
 Post subject: Re: Animation and alpha
PostPosted: Thu Jul 05, 2012 1:46 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
This is a design issue with Slick's "setAlpha" method. Personally I think it's something that should be deprecated/removed, although I'm not sure whether others would agree.

Generally speaking you should just stick to using Color filters when trying to fade an image:
Code:
alphaFilter = new Color(1f, 1f, 1f, 1f);
...

alphaFilter.a = 0.5f;
animation.draw(x, y, width, height, alphaFilter);


Top
 Profile  
 
 Post subject: Re: Animation and alpha
PostPosted: Thu Jul 05, 2012 7:26 am 
Offline

Joined: Mon Sep 12, 2011 9:07 am
Posts: 14
I also find a way to do it:

Code:
Image current = animation.getCurrentFrame();
current.setAlpha(0.75f);
current.draw(x, y);


Which method between davedes and this seems to be better ?

_________________
If you search on google, you find forums where users tell you to search on google...


Top
 Profile  
 
 Post subject: Re: Animation and alpha
PostPosted: Thu Jul 05, 2012 11:11 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Mine creates less garbage for the GC, but either will work.


Top
 Profile  
 
 Post subject: Re: Animation and alpha
PostPosted: Wed Jul 18, 2012 8:31 am 
Offline

Joined: Mon Sep 12, 2011 9:07 am
Posts: 14
Ok ! thanks a lot !

_________________
If you search on google, you find forums where users tell you to search on google...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group