简体   繁体   English

Java-绘制外部框架

[英]Java - Draw'ing outside frame

I am developing a 2d game; 我正在开发2D游戏; I am currently developing a system of movement of the camera on the map, I used the following method: my camera has own coordinates - x,y; 我目前正在开发相机在地图上的移动系统,我使用了以下方法:我的相机具有自己的坐标-x,y; I have ArrayList with all my sprites for map with their coords from 0 to mapSize, every sprite has a Draw function, which looks simply like 我有ArrayList,其中包含我所有的sprite,其坐标从0到mapSize,每个Sprite都有一个Draw函数,看起来就像

g2d.drawImage(texture, getX(), getY(), getX() + getSizeX(), y + getSizeY(), 0, 0, getSizeX(), getSizeY(), null); g2d.drawImage(纹理,getX(),getY(),getX()+ getSizeX(),y + getSizeY(),0,0,getSizeX(),getSizeY(),null);

I'm always drawing all my sprites, without checking are they visible or not; 我一直在画所有的精灵,而不检查它们是否可见; Whether there is a load on the computer at this drawing (when drawing textures that very far away from screen size)? 在此绘图上(当绘图纹理与屏幕尺寸相距很远时),计算机上是否有负载? Do I need to check whether the object is visible before rendering? 渲染之前是否需要检查对象是否可见?

My main DrawAll function contains(): 我的主要DrawAll函数包含():

public void DrawAll(graphics2D g2d){

    g2d.translate(-playerCamera.getX(), -playerCamera.getY());

    for (int i = 0; i < mapSprites.size(); i++) {
        mapSprites.get(i).Draw(g2d);
    }

    g2d.translate(-playerCamera.getX(), -playerCamera.getY());

    drawSomeStrings, etc....

}

This is not very good, because lines that were drawn after second translate may twitch when moving the screen. 这不是很好,因为在移动屏幕时,第二次平移后绘制的线条可能会抽动。 Should I give translate up and do the offset coordinates manually in each object\\sprite's Draw function? 我是否应该放弃平移并在每个对象\\精灵的Draw函数中手动执行偏移坐标?

graphics2D will clip your drawing. graphics2D将剪切您的图形。 So it does not impact too much. 因此它不会产生太大影响。 If you have a lot of sprites, you should consider using a SpatialIndex to select which Sprite is in the screen. 如果您有很多精灵,则应考虑使用SpatialIndex来选择屏幕中的精灵。 ( https://github.com/aled/jsi ) https://github.com/aled/jsi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM