Reputation: 436
I am creating a skyline game as a side project for fun, and I was having trouble when I would get to texturing the walls of the buildings, I currently am just drawing a polygon to that area, but I want to know if there is a way to texture it such that a texture like this:
could be rendered like this:
Here is an image of the game, and the parts I want to texture are the gray walls of the buildings.
I know I can do this by creating a separate rendering system that draws it pixel by pixel, but I am trying to avoid that.
My specific question is if there exists methods in Java's Graphics or something similar that can accomplish this.
Upvotes: 0
Views: 206
Reputation: 3454
if you want to perform a shear transformation AffineTransformation is your solution.
AffineTransform at;
double shx, shy;
at.shear(shx, shy);
use the AffineTransformation when draw image - sadly it's not so obvious that you have to use Graphics2D for that purpose
@Override
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D)g;
BufferedImage img = ...;
AffineTransform at = ...;
g2d.drawImage(img, at, null);//null-param is the ImageObserver
....
}
Upvotes: 1