How can I make my player go though transparent objects
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(); }
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(); }
// 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 }