Lachie James
Lachie James

Reputation: 43

Using the slick2d library, how do I get the value of 'delta' into the render() method?

So I'm doing my first java assignment, which is to make a very basic game using slick2d. This is what I have so far

Notice the little yellow bus on the left hand side. I need this bus to be moving from left to right across the screen. Rendering the bus as stationary is easy:

public void render(Graphics g) {
    bus.draw(0, 432);
}

But I need to use 'delta' to move it from left to right. Now I know that the update method has delta in it:

public void update(Input input, int delta) throws SlickException {
}

but the render method does not.

How can I get the value of delta into the render method?

(Without changing the method signatures cause apparently that screws everything up when using slick2d)

Upvotes: 0

Views: 97

Answers (1)

LOLWTFasdasd asdad
LOLWTFasdasd asdad

Reputation: 2943

One possibility would be to save the delta value in an attribute of your class. So on top of your class simply:

private int deltaValue;

and inside your update method:

public void update(Input input, int delta) throws SlickException {
    deltaValue = delta;
}

Then you can access your delta value inside your render method:

public void render(Graphics g) {
  //  System.out.println(deltaValue);
}

Upvotes: 0

Related Questions