Will java draw off screen elements?

Parzavil :

I am building a simple, top down, 2D game in which players will spawn in a world of a limited size.The world may be relatively large (5000 by 5000 pixels) and will have about 6 or 7 clients connected to it at once.

Items on the clients screen will be drawn relative to there position, so that they always appear in the center, and the objects are drawn around them.

super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.fillRect(objectX-playerX, objectY-playerY, objectWidth, objectHeight);

This will draw the items in the correct position, but will java try and draw the objects that have a co-ordinate off screen? Like (-100, -350)

Are there some rendering hints I can use to prevent this?

Super Shark :

Use clip. clip define draw area.

int screenWidth = 1920;
int screenHeight = 1080;

Rectangle clipShape = new Rectangle(0, 0, screenWidth, screenHeight);
g.setClip(clipShape);

at this code, only pixels in "clipShape" will be draw.

there's many way to define clip. so choose any thing u like and use :)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=104330&siteId=1