So i have a problem with LibGDX, i am creating a game where there are spikes.
I have created a separate class which contains a run method which runs every five seconds.
I want to run a method from another class and create a new spike on the screen.
Since i have a new account i cannot post pictures.
But this is for the initializing of the timer:
@Override
public void create ()
{
timer = new Timer();
timer.schedule(new SpikeHandler(), 0, 5000);
}
And this is for the create a spike method:
public static void createNewSpike(int x, int y)
{
sb.draw(spike.spikeLeft, x, y);
}
And this is what happens every five seconds/the timer loop:
public class SpikeHandler extends TimerTask
{
public Random rand = new Random();
@Override
public void run()
{
if(GameStateManager.getState() == GameState.Playing && GameScreen.hasCountdowned == true)
{
GameScreen.sb.begin();
GameScreen.createNewSpike(rand.nextInt(150), rand.nextInt(150));
GameScreen.sb.end();
}
}
}
This is the error message I'm getting:
Exception in thread "Timer-0" java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL11.glDepthMask(GL11.java:1157)
at com.badlogic.gdx.backends.lwjgl.LwjglGL20.glDepthMask(LwjglGL20.java:256)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.begin(SpriteBatch.java:163)
at com.fam.dodge.SpikeHandler.run(SpikeHandler.java:17)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)