0

I'm getting crazy trying to draw a very simple rect and a text in order to just understand how it works with the slick 2d java library.

This is what I try:

g.setColor(Color.green);
g.fillRect(50, 50, 50 ,50);

g.setColor(Color.orange);
g.drawString("Write something", 100, 100);

I just got to have everything I draw either in green or orange, but not one green and the other orange, as I would like to do...

Can someone help me to figure this out ???

Many thanks in advance

Daepp
  • 21
  • 1
  • 4

3 Answers3

6

Your code seems to be correct, and works on my test-game. Are you running it in the appropriate method, public void render(GameContainer gc, Graphics g)?

Try to update your LWJGL and Slick2D libraries too.

Kyukon
  • 63
  • 1
  • 7
1

Imagine you're drawing the screen by hand. You pick up a green pen, and you draw a rectangle. Then you pick up an orange pen and draw the words. That's what you're telling Slick2D to do with your code. Don't change colors between the two drawing operations - just set the color, then draw both objects and they will come out as the same color.

When you change colors all shape/text operations you do after that will be in that color, until you change colors again.

jefflunt
  • 33,527
  • 7
  • 88
  • 126
0

I was also importing the java.awt.Color;, this library is incompatible with Slick2D.

To fix this replace the line import java.awt.Color; with import org.newdawn.slick.Color;.

YoungHobbit
  • 13,254
  • 9
  • 50
  • 73
Dan
  • 315
  • 2
  • 13