Hello!
Please consider these to pictures of my current WIP:
Unscaled:
http://www.javadaemon.com/pictures/scaling_problem.png
Scaled x2 in super render method:
http://www.javadaemon.com/pictures/scaling_problum.png
I’m using Slick2D by the way. The upper image shows the game, and it’s working as it should.
The second image, shows the result when I’m doing a g.scale(2,2); in the upper-most rendering method (the one in the “main” class).
I’m obviously missing something because that wasn’t quite the result I was looking for.
I’ve tried to multiply various different variables in the world-rendering, but it all just gave me wrong (though rahter interresting results).
Here it is, as it is when I am not trying to scale it:
@Override
public void render(GameContainer container, Graphics g)
throws SlickException {
// Draw the current tile map, and the actors in it
final TileMap map = model.getCurrentMap(); // Get the currently active (displayed) map from the game state
final SpriteSheet graphics = RessourceManager.getRessourceManager().getGraphics(); // Get the sprite sheet
Actor player = model.getPlayer();
int px = player.getWorldX();
int py = player.getWorldY();
// Sets the offset of the viewport, depending on the players location and the fact that
// the player is always the center of the viewport.
int viewportOffsetX = CENTER_OFFSET_X-(px);
int viewportOffsetY = CENTER_OFFSET_Y-(py);
// Check boundaries for viewport (for cropping purposes - we do not want to loop through and draw tiles
// which are outside the currently visible part of the map)
int firstVisibleX = ((int)-viewportOffsetX)/RessourceManager.TILE_WIDTH;
int lastVisibleX = Math.min(firstVisibleX+fitsInViewX+1, map.getWidth());
int firstVisibleY = ((int)-viewportOffsetY)/RessourceManager.TILE_HEIGHT;
int lastVisibleY = Math.min(firstVisibleY+fitsInViewY+1, map.getHeight());
graphics.startUse(); // Until released by endUse, only graphics from this sprite sheet will be drawn, but they will be drawn faster.
// Draw all visible tiles (with contents, if any)
for (int x = firstVisibleX; x<lastVisibleX; x++)
{
int currentXOffset = x*RessourceManager.TILE_WIDTH;
for (int y = firstVisibleY; y<lastVisibleY; y++)
{
int currentYOffset = y*RessourceManager.TILE_HEIGHT;
if (x >= 0 && y >=0)
{
// Rendering the first layer - raw tiles
Tile tile = map.getTile(x, y);
if (tile != null)
{
// Using the image reference key from the tile's type, retrieve and draw the terrain image
TILE_TYPE type = map.getTile(x, y).getType();
RessourceManager.IMAGE image = type.getImage();
Image imageToDraw = graphics.getSubImage(image.getSheetColumn(), image.getSheetRow());
imageToDraw.drawEmbedded(viewportOffsetX+currentXOffset, viewportOffsetY+currentYOffset, RessourceManager.TILE_WIDTH, RessourceManager.TILE_HEIGHT); // Note that the drawEmbedded method is used to make use of the enhanced drawing speed.
}
}
}
}
// Draw all characters
for (int x = firstVisibleX; x<lastVisibleX; x++)
{
for (int y = firstVisibleY; y<lastVisibleY; y++)
{
if (x >= 0 && y >=0)
{
// Rendering second layer - characters
Actor actor = model.getCharacterManager().getCharacter(x, y);
if (actor != null)
{
Animation currentAnimation1 = actor.getCurrentAnimation();
currentAnimation1.getCurrentFrame().drawEmbedded(viewportOffsetX+actor.getWorldX(),
viewportOffsetY+actor.getWorldY(), RessourceManager.TILE_WIDTH, RessourceManager.TILE_HEIGHT);
}
}
}
}
// Draw the player's current animation
Animation currentAnimation = player.getCurrentAnimation();
currentAnimation.getCurrentFrame().drawEmbedded(viewportOffsetX+player.getWorldX(), viewportOffsetY+player.getWorldY(), RessourceManager.TILE_WIDTH, RessourceManager.TILE_HEIGHT);
graphics.endUse(); // Release, so that graphics that are not in the sprite sheet can be used again.
}
I think it’s pretty self-explainatory what it does, so I wont go into greater detail about that.
I have never scaled anything successfully, so if you could provide me with a little info on what I got to look out for, that would be really nice
Thanks for the help guys!