This site requires JavaScript, please enable it in your browser!
Greenfoot back
SWAG
SWAG wrote ...

2013/6/1

Transparency

1
2
3
4
SWAG SWAG

2013/6/1

#
How can I make my player go though transparent objects
danpost danpost

2013/6/1

#
Do you have collision checking that prevents the player from going through them? if so, what is the code and what is/are the name(s) of the transparent objects?
SWAG SWAG

2013/6/1

#
danpost wrote...
Do you have collision checking that prevents the player from going through them? if so, what is the code and what is/are the name(s) of the transparent objects?
My platform is a hill and therefore has a round shape but has a transparent canvas around it, when I put the picture in the game my actors walk on the transparent canvas. I would like it so that my actors will go though the transparent canvas and walk on the hill.
danpost danpost

2013/6/1

#
What you need, then, is to use the color of the image to control how far your actor can 'fall'. That would involve using their locations and computing what point of the platform image is at the foot of you actor and checking the color at that point.
SWAG SWAG

2013/6/1

#
danpost wrote...
What you need, then, is to use the color of the image to control how far your actor can 'fall'. That would involve using their locations and computing what point of the platform image is at the foot of you actor and checking the color at that point.
The picture I have is multi-colored. Is there any easier way?
JetLennit JetLennit

2013/6/1

#
What about checking to see if getTransparency() is not 0?
danpost danpost

2013/6/1

#
'getTransparency' is a GreenfootImage method that check for a value that deals with the image on a whole (not individual pixels of the image).
danpost danpost

2013/6/1

#
You only have to look for the transparent pixels, whose alpha value is zero (or close to it).
SWAG SWAG

2013/6/1

#
danpost wrote...
You only have to look for the transparent pixels, whose alpha value is zero (or close to it).
How do I do that?
danpost danpost

2013/6/2

#
First when intersection between the two objects occur, you would take the difference in both the x and y coordinates of the objects. You would then subtract those differences from half the width and height of the image you need the color off of. That will give you the point from which you need the color from. Finally use 'getAlpha' on 'getColorAt' on 'getImage' of the actor you need the alpha value from.
Robert2.0 Robert2.0

2013/6/2

#
danpost wrote...
First when intersection between the two objects occur, you would take the difference in both the x and y coordinates of the objects. You would then subtract those differences from half the width and height of the image you need the color off of. That will give you the point from which you need the color from. Finally use 'getAlpha' on 'getColorAt' on 'getImage' of the actor you need the alpha value from.
I having the same problem with transparency. Could you show some code please. I didn't really understand the explain above.
danpost danpost

2013/6/2

#
From the Player class:
Actor platform = getOneIntersectingObject(Platform.class);
if (platform != null)
{
    while (getAlphaAtFoot(platform) > 12) setLocation(getX(), getY()-1);
}
// using the following method to get the alpha value of the color at foot of actor
private int getAlphaAtFoot(Actor actor)
{
    int xOff = actor.getImage().getWidth()/2-(actor.getX()-getX());
    int yOff = actor.getImage().getHeight()/2-(actor.getY()-(getY()+getImage().getHeight()/2));
    return actor.getColorAt(xOff, yOff).getAlpha();
}
Robert2.0 Robert2.0

2013/6/2

#
danpost wrote...
From the Player class:
Actor platform = getOneIntersectingObject(Platform.class);
if (platform != null)
{
    while (getAlphaAtFoot(platform) > 12) setLocation(getX(), getY()-1);
}
// using the following method to get the alpha value of the color at foot of actor
private int getAlphaAtFoot(Actor actor)
{
    int xOff = actor.getImage().getWidth()/2-(actor.getX()-getX());
    int yOff = actor.getImage().getHeight()/2-(actor.getY()-(getY()+getImage().getHeight()/2));
    return actor.getColorAt(xOff, yOff).getAlpha();
}
I get the error cannot find symbol - method getColorAt(int,int)
danpost danpost

2013/6/2

#
Here is a break-down of the steps involved:
// first, get a reference to the platform (if intersecting it)
Actor platform = getOneIntersectingObject(Platform.class);
if (platform != null) // only process if a platform is found
{
    while (getAlphaAtFoot(platform) > 12) // do until fairly transparent
    {
         setLocation(getX(), getY()-1); // move up one pixel
    }
}
// using the following method to get the alpha value of the color at foot of actor
/** this method returns the alpha value of the pixel on the platform image
 * that intersects the players image at the center of its bottom edge.
 * NOTE: the center of the bottom edge of the player MUST intersect the image
 * of the actor given in the argument for this method to work.
 */ 
private int getAlphaAtFoot(Actor actor) // actor is the platform in your case
{
    int playerX = getX(); // the x at center of player
    int playerY = getY()+getImage().getHeight()/2; // the y at foot of player
    int xDiff = actor.getX()-playerX; // the difference along the x-axis
    int yDiff = actor.getY()-playerY; // and y-axis of the two actors

    int xOff = actor.getImage().getWidth()/2-xDiff; // the pixel's x
    int yOff = actor.getImage().getHeight()/2-yDiff; // and y offsets in the image
    return actor.getImage().getColorAt(xOff, yOff).getAlpha(); // return the alpha of that pixel's color
}
danpost danpost

2013/6/2

#
I missed the 'getImage()' call in the last statement. Refer to the break-down above.
There are more replies on the next page.
1
2
3
4