Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Slick2D - Dynamically Creating Objects
    text
    copied!<p>Okay, so I understand that Images can be rendered in the render statement. I do have one question, though. Is there a way I can create an object dynamically (e.g. Plane class) and have an Image be created and rendered via a String called texture? For example, if I have a class called Bullet, how can I dynamically create the Image as I run</p> <pre><code>Bullet myBullet = new Bullet(); </code></pre> <p>? I would really appreciate some help.</p> <p>Example:</p> <pre><code>class Bullet { public float x, y = 0; public float rotation = 0; public void bullet(posX, posY) { x = posX; y = posY; } </code></pre> <p>Also, how can I make it loop a method automatically (I already have a loop running in main class, but how do I append this to the block?)?</p> <pre><code>public void update() { x += 2 * Math.cos((Math.PI / 180) * rotation); y += 2 * Math.sin((Math.PI / 180) * rotation); } } </code></pre> <p>Thanks,</p> <p>Joe</p> <p><strong>EDIT:</strong> By create Image, I mean to also render it.</p> <p>Or, for a game I am working on that behaves somewhat like Frogger, how do I make this class's Image called texture render when I declare it and add it's update statement to the update() loop in the BasicGame file? package misc;</p> <pre><code>import mobile.MobileOctopus; import org.newdawn.slick.Image; import org.newdawn.slick.SlickException; public class Current { public Image texture; public float x, y = 0; MobileOctopus player; public Current(int posY, MobileOctopus character) throws SlickException { texture = new Image("res/current.png"); x = 0; y = posY; player = character; } public void update() { x -= 3; if(x &lt; -380) { x = 0; } if(player.y + 32 &gt; y &amp;&amp; player.y + 32 &lt; y + 32) { player.x -= 3; } } } </code></pre> <p>The Current class moves the player left when he is inside it. But, how can I do said above by calling</p> <pre><code>Current myCurrent = new Current(100, player); </code></pre>
 

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