Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 2:59 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Apr 30, 2012 12:03 pm 
Offline

Joined: Sun Apr 29, 2012 10:38 am
Posts: 13
I tried to set alpha for spritesheets, but it doesn't seem to have any effect, example below:

Code:
spriteSheet = new SpriteSheet(imageLocation, TILESIZE, TILESIZE);
spriteSheet.setAlpha(0.1f);
n.addFrame(spriteSheet.getSprite(0, 0), 150);


I guess this is the intended effect, right?
Or I am doing something wrong?
Is there a possibility to change the alpha for a whole SpriteSheet?


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 4:59 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Yeah, it's a bug. SpriteSheet extends Image, which IMO is kinda poor design, but some things were forgotten like setAlpha, setRotation, etc. Added it to the TODO list...

Since each sprite in a sheet is its own Image class, you can apply individual alphas to each via getSubImage(cx, cy).setAlpha. However, I'd recommend learning to apply alpha manually, as setAlpha may become deprecated in future versions of Slick.

Code:
init...
    myFilter = new Color(1f, 1f, 1f, 0.5f);   //50%
    myFilter2 = new Color(1f, 1f, 1f, 0.25f); //25%

render...
    //simple draw
    sheet.getSubImage(cx, cy).draw(x, y, myFilter);

    //embedded draw, more efficient
    sheet.startUse();

    //draw sprites with 50% alpha
    graphics.setColor(myFilter);
    sheet.getSubImage(cx, cy).drawEmbedded(x1, y1, w, h);
    sheet.getSubImage(cx2, cy2).drawEmbedded(x2, y2, w, h);

    //draw sprites with 25% alpha
    graphics.setColor(myFilter2);
    sheet.getSubImage(cx2, cy2).drawEmbedded(x3, y3, w, h);
    sheet.getSubImage(cx2, cy2).drawEmbedded(x4, y4, w, h);

    sheet.endUse();


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 10:35 pm 
Offline

Joined: Sun Apr 29, 2012 10:38 am
Posts: 13
thx!!!

Quote:
However, I'd recommend learning to apply alpha manually, as setAlpha may become deprecated in future versions of Slick.

interesting, why will setAlpha be axed?
I mean the filter feature is nice, but basically it is a bit "low-level".
Especially, I don't see how removing setAlpha is really related with one of the goals:
Quote:
* Provide the tools required for most simple games out of the box


my current impression - I may be terribly wrong - on the documentation (e.g. why should we mention that angles are in radians, why would anyone in a 2D game library think about using so daily-lifely like degrees!?) and tutorial stuff is that the "library" has a kind of an elitist touch, which would be ok if it would be written in C or Assembler, well but it is Java ;) but I guess that comes from the OpenGL background.


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 11:11 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
In short, it's poor design to put things like alpha/rotation/etc. in the Image class, which should primarily just be a container with sub-image coordinates and a center point. Alpha/rotation falls in the same category as x/y/width/height values, which should be implemented by the user in an Entity-like class. Just like you don't see Image.setX/Y, you also shouldn't see Image.setAlpha.

Furthermore, it creates conflict & ambiguity when tinting an image:
Code:
image.setAlpha(0.5f);
g.drawImage(image, x, y, myFilter); //<-- should myFilter's alpha override image alpha? or be multiplied by it?


Removing it is just my opinion, though, and I'm sure some other devs/users will disagree. So it probably won't get axed, at least for a long time.

Unfortunately, when setRotation/setAlpha was added, it wasn't really considered fully. drawEmbedded, drawFlash, SpriteSheet.draw, copy(), etc. don't take it into account, even though they potentially should. So now it's a matter of tracking down the various areas that were overlooked and fixing the bugs. ;) But the small dev team has other priorities...

Quote:
why should we mention that angles are in radians, why would anyone in a 2D game library think about using so daily-lifely like degrees!?

Is this sarcasm? Lots of beginners might not know what "radians" even means...


Top
 Profile  
 
PostPosted: Tue May 01, 2012 6:21 pm 
Offline

Joined: Sun Apr 29, 2012 10:38 am
Posts: 13
davedes wrote:
In short, it's poor design to put things like alpha/rotation/etc. in the Image class, which should primarily just be a container with sub-image coordinates and a center point. Alpha/rotation falls in the same category as x/y/width/height values, which should be implemented by the user in an Entity-like class. Just like you don't see Image.setX/Y, you also shouldn't see Image.setAlpha.

Furthermore, it creates conflict & ambiguity when tinting an image:
Code:
image.setAlpha(0.5f);
g.drawImage(image, x, y, myFilter); //<-- should myFilter's alpha override image alpha? or be multiplied by it?


thx a lot! I learned something, I like that!


Quote:
Quote:
why should we mention that angles are in radians, why would anyone in a 2D game library think about using so daily-lifely like degrees!?

Is this sarcasm? Lots of beginners might not know what "radians" even means...

YES, it is sarcasm:
Code:
angle
protected float angle
    Angle to rotate the image to.

http://slick.cokeandcode.com/javadoc/or ... html#angle

my first post on this forum was about this, but to this day it wasn't approved :(
now, the odd thing is, I found out that it is in radians, but now I found that:
Quote:
setRotation

public void setRotation(float angle)

Set the angle to rotate this image to. The angle will be normalized to be 0 <= angle < 360. The image will be rotated around its center.

Parameters:
angle - The angle to be set

http://slick.cokeandcode.com/javadoc/or ... 28float%29

but being normalized doesn't really imply that is in degree also?

or my memory that it was in radians is wrong or ???
well, back to the facts: the documentation is missing what kind of unit it is, which in my opinion is crucial.


Top
 Profile  
 
PostPosted: Thu May 03, 2012 5:38 pm 
Offline
Oldbie
User avatar

Joined: Thu Jan 13, 2011 4:42 pm
Posts: 349
that's a good point. I've spent a few hours myself figuring out why angles weren't working properly. I wonder if any of us developers has access to the documentation; that shouldn't be hard to change.

_________________
"Artificial intelligence will never be a match for human stupidity" - "Jamos Kennedynos"


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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