Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i think the answer by @mantrid should fix your problem. as far as performance goes ... there are some obvious "sins" in your code: </p> <p><strong>Don't draw an image into an image to draw an image</strong></p> <pre><code>public void drawImage(BufferedImage img, double x, double y, double scale){ x -= xScroll; y -= yScroll; BufferedImage image = new BufferedImage((int)(img.getWidth()*scale), (int)(img.getHeight()*scale), BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); g.drawImage(img, 0, 0, (int)(img.getWidth()*scale), (int)(img.getHeight()*scale), null); g2d.drawImage(image, (int)x, (int)y, null); g.dispose(); } </code></pre> <p>I don't see the point of this. Why not just do this: </p> <pre><code>public void drawImage(BufferedImage img, double x, double y, double scale){ g2d.drawImage(img, (int)(x-xScroll), (int)(y-yScroll), (int)(img.getWidth()*scale), (int)(img.getHeight()*scale), null); } </code></pre> <p><strong>AAAAAAAAAAAAA</strong></p> <p>The next one actually burnt my eyes </p> <pre><code>public void drawRectangle(double x, double y, int xs, int ys, int colour){ if(xs &lt;= 0){ return; } x -= xScroll; y -= yScroll; BufferedImage image = new BufferedImage(xs, ys, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) image.getGraphics(); g.setColor(new Color(colour)); g.fillRect(0, 0, xs, ys); g2d.drawImage(image, (int)x, (int)y, null); g.dispose(); } </code></pre> <p>Why? This is so much simpler and quicker: </p> <pre><code>public void drawRectangle(double x, double y, int xs, int ys, int colour){ if(xs &lt;= 0) return; g2d.setColor(new Color(colour)); g2d.fillRect((int)(x-xScroll), (int)(y-yScroll), xs, ys); } </code></pre> <p>The same goes for the <code>drawImageRotated</code> and <code>drawString</code>. Just draw to the g2d buffer directly, what are you afraid of? </p> <p><strong>drawImageBlurred</strong></p> <p>First of all... you're doing it again! Second: You seem to be applying a convolve operation to an image on each frame, why not just do that operation once (e.g. at the start of the app, or even better yet, in an image editing program). </p> <p>I don't mean this in a bad way at all, but you are clearly not very experienced with programming in general. I think you could take a look at processing (<a href="http://processing.org">http://processing.org</a>). I'm sort of biased here because i'm using it myself almost everyday. It is a great learning and prototyping environment written in java that should allow you to stop thinking about implementation details (like flipping buffers) and focus on what you really care for (make a game!). </p> <p>Alright, hope what i said makes sense. Good luck with your coding! :) </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload