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
Bullet myBullet = new Bullet();
? I would really appreciate some help.
Example:
class Bullet
{
public float x, y = 0;
public float rotation = 0;
public void bullet(posX, posY)
{
x = posX;
y = posY;
}
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?)?
public void update() {
x += 2 * Math.cos((Math.PI / 180) * rotation);
y += 2 * Math.sin((Math.PI / 180) * rotation);
}
}
Thanks,
Joe
EDIT: By create Image, I mean to also render it.
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;
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 < -380)
{
x = 0;
}
if(player.y + 32 > y && player.y + 32 < y + 32)
{
player.x -= 3;
}
}
}
The Current class moves the player left when he is inside it. But, how can I do said above by calling
Current myCurrent = new Current(100, player);