Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot render SurfaceLayer during paint method
    primarykey
    data
    text
    <p><strong>Edit</strong> This was a bug that has been fixed in <a href="https://github.com/threerings/playn/commit/137ce50dddd2716f84c38ec1568d7ae5a368434b" rel="nofollow">https://github.com/threerings/playn/commit/137ce50dddd2716f84c38ec1568d7ae5a368434b</a>. See Par Eklund's answer for details. </p> <p>Before I begin: I am a novice at game programming in general so it's very likely that I have a fundamental misunderstanding of the tools I am using. However I'll push on with my question...</p> <p>Whenever I try to draw something on my Surface Layer during the <code>paint</code> method I get a black screen. If I draw during the <code>init</code> method it shows up OK. </p> <p>I am trying to replicate the code under the <em>Surface Layer</em> banner <a href="https://developers.google.com/playn/devguide/rendering" rel="nofollow">here</a>. The code in question is this:</p> <pre><code>public void paint() { // Draw 100 random peas imperatively. surf.clear(0); for (int i = 0; i &lt; 100; ++i) { int x = (int)(random() * WIDTH); int y = (int)(random() * HEIGHT); surf.drawImage(pea, x, y); } } </code></pre> <p>I am using PlayN 1.4 so while that code doesn't directly match up to what I am writing I thought I at least had the equivalent (except I am drawing white rectangles):</p> <pre><code>public void paint(final float alpha) { surfaceLayer.surface().clear(); surfaceLayer.surface().setFillColor(Color.rgb(255, 255, 255)); for (int i = 0; i &lt; 100; ++i) { int x = (int) (Math.random() * width); int y = (int) (Math.random() * height); surfaceLayer.surface().fillRect(x, y, 5, 5); } } </code></pre> <p>Nothing is rendered to the screen. If I move that code into the <code>init</code> method it renders as expected.</p> <p>Now <strong>interestingly</strong> if I make PlayN 1.3.1 project and use the <em>exact same code</em> it renders fine during the paint method (given that I'm still using the exact same code I'm not sure what version the PlayN website is using in its example code...).</p> <p>What have I missed here? Has 1.4 changed something to do with the Surface Layer and I must use it differently now? Thanks.</p>
    singulars
    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. 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