Show Posts
|
|
Pages: [1] 2
|
|
1
|
Game Development / Newbie & Debugging Questions / Re: Creating GUI elements in Slick2d
|
on: 2012-12-06 12:24:50
|
Im sure you could just create your own, from what I believe, you could just create multiple boxes added together to create the menu when right clicked.
I think it would be almost easier to create it yourself then learning a GUI library for LWJGL.
I don't see how i'd be able to easily create the menu and register click on the items. And I agree with the guy who said to make one thread instead of 500.
I'll tell you exactly the same as i told him - I've created a topic for each question to keep the forums searchable. This is definitely optimizing the asking of already asked- and answered questions. Besides, half of your answers is just lacky ideas which does not lead anywhere, and the remaining half is just useless posts which i assume is to boost your postcounter. Have a nice day, and keep in mind, you don't have to reply to my threads. :-)
|
|
|
|
|
2
|
Game Development / Newbie & Debugging Questions / Creating GUI elements in Slick2d
|
on: 2012-12-06 12:11:01
|
|
I want to create a small menu that pops out when someone rightclicks a player. It should pop out from the players character. Should i use a GUI Library for this? If yes, which GUI would be better for this task? (Using BasicGame). If not, how would i be able to achieve this? (It should be rendered in the render method)
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / Re: Slick input keys
|
on: 2012-12-05 22:23:36
|
Most people here are probably not using Slick2D.
Seeing as Slick has its Input class already made and keys premade, Im not sure. If you were going to use just LWJGL Keyboard class and create the InputHandler class yourself, it would be easy.
Well, since Slick is built on LWJGL, wouldn't it be possible to implement that in some way?
|
|
|
|
|
9
|
Game Development / Newbie & Debugging Questions / Re: Slick - custom fonts and linebreaks
|
on: 2012-12-05 18:25:03
|
If you have several Slick questions, ask them all in a single thread rather than cluttering the forums.
TrueTypeFont is deprecated. Line breaks should work with angel code fonts and unicode fonts.
Well, i guessed it made more sense creating a topic for each question, to be search-friendly. Thank you for the answer
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Slick - custom fonts and linebreaks
|
on: 2012-12-05 09:31:29
|
It seems that Slick doesn't accept the \n linebreak when using custom fonts. When using the default font, my linebreaks works just fine. However, when i use: 1 2
| this.font = new TrueTypeFont(awtFont, true); this.color = new Color(210, 234, 196); |
and: 1 2
| g.setFont(font); g.drawString(message, 100, 100); |
the linebreaks are converted to spaces. How can i avoid this?
|
|
|
|
|
15
|
Game Development / Newbie & Debugging Questions / Slick input keys
|
on: 2012-12-05 08:51:17
|
I'm making a chat and i need to catch the Questionmark key (?), however i can't figure out how to do that, since i can't find it in Slicks keylist. The list is attached below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| public static final int ANY_CONTROLLER = -1; private static final int MAX_BUTTONS = 100; public static final int KEY_ESCAPE = 1; public static final int KEY_1 = 2; public static final int KEY_2 = 3; public static final int KEY_3 = 4; public static final int KEY_4 = 5; public static final int KEY_5 = 6; public static final int KEY_6 = 7; public static final int KEY_7 = 8; public static final int KEY_8 = 9; public static final int KEY_9 = 10; public static final int KEY_0 = 11; public static final int KEY_MINUS = 12; public static final int KEY_EQUALS = 13; public static final int KEY_BACK = 14; public static final int KEY_TAB = 15; public static final int KEY_Q = 16; public static final int KEY_W = 17; public static final int KEY_E = 18; public static final int KEY_R = 19; public static final int KEY_T = 20; public static final int KEY_Y = 21; public static final int KEY_U = 22; public static final int KEY_I = 23; public static final int KEY_O = 24; public static final int KEY_P = 25; public static final int KEY_LBRACKET = 26; public static final int KEY_RBRACKET = 27; public static final int KEY_RETURN = 28; public static final int KEY_ENTER = 28; public static final int KEY_LCONTROL = 29; public static final int KEY_A = 30; public static final int KEY_S = 31; public static final int KEY_D = 32; public static final int KEY_F = 33; public static final int KEY_G = 34; public static final int KEY_H = 35; public static final int KEY_J = 36; public static final int KEY_K = 37; public static final int KEY_L = 38; public static final int KEY_SEMICOLON = 39; public static final int KEY_APOSTROPHE = 40; public static final int KEY_GRAVE = 41; public static final int KEY_LSHIFT = 42; public static final int KEY_BACKSLASH = 43; public static final int KEY_Z = 44; public static final int KEY_X = 45; public static final int KEY_C = 46; public static final int KEY_V = 47; public static final int KEY_B = 48; public static final int KEY_N = 49; public static final int KEY_M = 50; public static final int KEY_COMMA = 51; public static final int KEY_PERIOD = 52; public static final int KEY_SLASH = 53; public static final int KEY_RSHIFT = 54; public static final int KEY_MULTIPLY = 55; public static final int KEY_LMENU = 56; public static final int KEY_SPACE = 57; public static final int KEY_CAPITAL = 58; public static final int KEY_F1 = 59; public static final int KEY_F2 = 60; public static final int KEY_F3 = 61; public static final int KEY_F4 = 62; public static final int KEY_F5 = 63; public static final int KEY_F6 = 64; public static final int KEY_F7 = 65; public static final int KEY_F8 = 66; public static final int KEY_F9 = 67; public static final int KEY_F10 = 68; public static final int KEY_NUMLOCK = 69; public static final int KEY_SCROLL = 70; public static final int KEY_NUMPAD7 = 71; public static final int KEY_NUMPAD8 = 72; public static final int KEY_NUMPAD9 = 73; public static final int KEY_SUBTRACT = 74; public static final int KEY_NUMPAD4 = 75; public static final int KEY_NUMPAD5 = 76; public static final int KEY_NUMPAD6 = 77; public static final int KEY_ADD = 78; public static final int KEY_NUMPAD1 = 79; public static final int KEY_NUMPAD2 = 80; public static final int KEY_NUMPAD3 = 81; public static final int KEY_NUMPAD0 = 82; public static final int KEY_DECIMAL = 83; public static final int KEY_F11 = 87; public static final int KEY_F12 = 88; public static final int KEY_F13 = 100; public static final int KEY_F14 = 101; public static final int KEY_F15 = 102; public static final int KEY_KANA = 112; public static final int KEY_CONVERT = 121; public static final int KEY_NOCONVERT = 123; public static final int KEY_YEN = 125; public static final int KEY_NUMPADEQUALS = 141; public static final int KEY_CIRCUMFLEX = 144; public static final int KEY_AT = 145; public static final int KEY_COLON = 146; public static final int KEY_UNDERLINE = 147; public static final int KEY_KANJI = 148; public static final int KEY_STOP = 149; public static final int KEY_AX = 150; public static final int KEY_UNLABELED = 151; public static final int KEY_NUMPADENTER = 156; public static final int KEY_RCONTROL = 157; public static final int KEY_NUMPADCOMMA = 179; public static final int KEY_DIVIDE = 181; public static final int KEY_SYSRQ = 183; public static final int KEY_RMENU = 184; public static final int KEY_PAUSE = 197; public static final int KEY_HOME = 199; public static final int KEY_UP = 200; public static final int KEY_PRIOR = 201; public static final int KEY_LEFT = 203; public static final int KEY_RIGHT = 205; public static final int KEY_END = 207; public static final int KEY_DOWN = 208; public static final int KEY_NEXT = 209; public static final int KEY_INSERT = 210; public static final int KEY_DELETE = 211; public static final int KEY_LWIN = 219; public static final int KEY_RWIN = 220; public static final int KEY_APPS = 221; public static final int KEY_POWER = 222; public static final int KEY_SLEEP = 223; public static final int KEY_LALT = 56; public static final int KEY_RALT = 184; private static final int LEFT = 0; private static final int RIGHT = 1; private static final int UP = 2; private static final int DOWN = 3; private static final int BUTTON1 = 4; private static final int BUTTON2 = 5; private static final int BUTTON3 = 6; private static final int BUTTON4 = 7; private static final int BUTTON5 = 8; private static final int BUTTON6 = 9; private static final int BUTTON7 = 10; private static final int BUTTON8 = 11; private static final int BUTTON9 = 12; private static final int BUTTON10 = 13; public static final int MOUSE_LEFT_BUTTON = 0; public static final int MOUSE_RIGHT_BUTTON = 1; public static final int MOUSE_MIDDLE_BUTTON = 2; private static boolean controllersInited; private static ArrayList controllers; private int lastMouseX; private int lastMouseY; protected boolean[] mousePressed; private boolean[][] controllerPressed; protected char[] keys; protected boolean[] pressed; protected long[] nextRepeat; private boolean[][] controls; protected boolean consumed; protected HashSet allListeners; protected ArrayList keyListeners; protected ArrayList keyListenersToAdd; protected ArrayList mouseListeners; protected ArrayList mouseListenersToAdd; protected ArrayList controllerListeners; private int wheel; private int height; private boolean displayActive; private boolean keyRepeat; private int keyRepeatInitial; private int keyRepeatInterval; private boolean paused; private float scaleX; private float scaleY; private float xoffset; private float yoffset; private int doubleClickDelay; private long doubleClickTimeout; private int clickX; private int clickY; private int clickButton; private int pressedX; private int pressedY; private int mouseClickTolerance; |
|
|
|
|
|
16
|
Game Development / Newbie & Debugging Questions / Gameserver makes computer sweat
|
on: 2012-12-05 08:34:08
|
I've coded a gameserver which works very well. However, whenever it's running, my computers fan goes crazy. I've been looking through the code, and i can't really figure out why. The code is attached below, i hope someone can see what causes this! :-) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| public class NFTServer {
long timeNow = System.currentTimeMillis(); Server server; Board board; HashSet<Character> loggedIn = new HashSet(); ArrayList<Player> playerList;
public NFTServer() throws IOException { playerList = new ArrayList<Player>(); board = new Board(); server = new Server() { protected Connection newConnection() { return new CharacterConnection(); } };
Network.register(server);
server.addListener(new Listener() { public void received(Connection c, Object object) { CharacterConnection connection = (CharacterConnection) c;
if (object instanceof Login) { String name = ((Login) object).name; int playerId = ((Login) object).playerId;
Message message = new Message(); message.message = "Welcome " + name + " id: " + playerId; connection.sendTCP(message); LoginAnswer answer = new LoginAnswer(); answer.playerId = playerId; connection.sendTCP(answer); Position randomPosition = board.getRandomPosition(); playerList.add(new Player(name, randomPosition.getPositionX(), randomPosition.getPositionY(), playerId)); connection.playerId = playerId; connection.name = name; } if (object instanceof RequestMove) { for (int i = 0; i < playerList.size(); i++) { Player currentPlayer = playerList.get(i); if (currentPlayer.getId() == connection.playerId) { int positionX = ((RequestMove) object).positionX; int positionY = ((RequestMove) object).positionY; Position position = new Position(positionX, positionY); currentPlayer.setPosition(board.convertCoord(position).getPositionX(), board.convertCoord(position).getPositionY()); } } } if (object instanceof ChatMessage) { String message = ((ChatMessage) object).message; int playerId = connection.playerId; for (int i = 0; i < playerList.size(); i++) { Player currentPlayer = playerList.get(i); if (currentPlayer.getId() == connection.playerId) { BroadMessage broadMessage = new BroadMessage(); broadMessage.message = message; broadMessage.playerId = playerId; server.sendToAllTCP(broadMessage); } } }
}
public void disconnected(Connection c) { CharacterConnection connection = (CharacterConnection) c; if (connection.name != null) { for (int i = 0; i < playerList.size(); i++) { Player currentPlayer = playerList.get(i); if (currentPlayer.getId() == connection.playerId) { playerList.remove(i); } } } } }); server.bind(Network.port); server.start();
JFrame frame = new JFrame("NFTServer"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { server.stop(); } }); frame.getContentPane().add(new JLabel(" Servervindue")); frame.setSize(320, 200); frame.setLocationRelativeTo(null); frame.setVisible(true);
while (true) { if (timeNow + 100 < System.currentTimeMillis()) { PlayerList toClient = new PlayerList(); toClient.persons = new ArrayList<Map<String, String>>(); for (int i = 0; i < playerList.size(); i++) { Player currentPlayer = playerList.get(i); Map<String, String> person = new HashMap<String, String>(); person.put("name", currentPlayer.getName()); person.put("playerId", "" + currentPlayer.getId()); person.put("posX", "" + currentPlayer.getX()); person.put("posY", "" + currentPlayer.getY()); toClient.persons.add(person); } server.sendToAllTCP(toClient);
timeNow = System.currentTimeMillis(); } } }
static class CharacterConnection extends Connection {
public String name; public int playerId; }
public static void main(String[] args) throws IOException { Log.set(Log.LEVEL_DEBUG); new NFTServer(); } } |
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / Re: Chat in Slick
|
on: 2012-12-04 11:09:31
|
For my first one attempt at a chat box, I created a ChatBox class, when enter is pressed, the input is disabled in the game, and only will only work in the ChatBox class. using org.lwjgl.input.Keyboard class I have a method 1 2 3
| public char getChatKey(){ return Keyboard.getEventCharacter(); } |
which is inside my InputHandler class. in my ChatBox class, I have an array of char's (because i get random chars in the way if I don't), I loop through the allowed keys if the key matches one of the chars in the array, it is then applied to the message string. Thank you for the answer! :-) The chat function is however a core functionality of my game, and should be available at all times without deactivating other movement (only moves by mouse). Where did you put that method?
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / Chat in Slick
|
on: 2012-12-04 10:44:18
|
I'm going to add chat functionality to a game i'm making, and i would probably be able to do it in a not-so-great way. How would one register each keypress and write it to the chat, without having to check each letter? i.e: 1 2 3
| if (input.isKeyPressed(input.KEY_A)) { this.text += "a"; } |
|
|
|
|
|
20
|
Game Development / Newbie & Debugging Questions / Re: Gameserver performance
|
on: 2012-12-04 10:42:11
|
|
Thank you all for some really great answers!
@saifix I would really prefer not having such lists on the clients, it doesn't suit me very well that the client handles anything on its own. The position system doesn't float, a player can jump from 1,1 to 16,15 at any time instantly, and the opposite as well :-) However, your answer was in-depth, and i'm going to look more into your suggestions. Thank you!
|
|
|
|
|
22
|
Game Development / Newbie & Debugging Questions / Re: Kryonet listener to Slick2d
|
on: 2012-12-03 18:48:50
|
Im not exactly sure what you want, but it would seem that line 21 should be simply 1
| this.name = ((LoginAnswer) object).name; |
That is exactly what i want, however that is not working. It seems that the codeblock in the Listener behaves like its own class. Netbeans suggests adding the field name in the Listener. (Line 15 that is) I sure hope there's a way to "break out" of this block
|
|
|
|
|
24
|
Game Development / Newbie & Debugging Questions / Re: Updating positions from MySQL database
|
on: 2012-12-03 18:37:49
|
My recommendation is ditch the database completely. Keep it in memory. You're trying to write a game like a web app, and the more you hang on to that model, the worse it's going to make the code and your experience writing it.
It should turn out as an applet. However, i did choose to write a gameserver, which just loads up the MySQL database at startup :-)
|
|
|
|
|
25
|
Game Development / Newbie & Debugging Questions / Kryonet listener to Slick2d
|
on: 2012-12-03 16:18:50
|
When KryoNet recieves the LoginAnswer package, i want to set the field of NFTClient String name (Line 4) to the ((LoginAnswer)object).name variable (Line 21) in order to use it in the Render method. How can i do that? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| public class NFTClient extends BasicGame {
Client client; String name;
public NFTClient() { super("Client"); client = new Client(); client.start();
Network.register(client);
client.addListener(new Listener.ThreadedListener(new Listener() { public void connected(Connection connection) { }
public void received(Connection connection, Object object) {
if (object instanceof LoginAnswer) { String name = ((LoginAnswer) object).name; }
}
public void disconnected(Connection connection) { System.exit(0); } }));
try { client.connect(5000, "localhost", Network.port); System.out.println("heJ"); } catch (IOException ex) { ex.printStackTrace(); } }
@Override public void init(GameContainer gc) throws SlickException { }
public void render(GameContainer gc, Graphics g) throws SlickException { g.drawString(this.name); }
@Override public void update(GameContainer gc, int delta) throws SlickException { }
public static void main(String[] args) throws SlickException {
Log.set(Log.LEVEL_DEBUG); AppGameContainer app = new AppGameContainer(new NFTClient());
app.setDisplayMode(768, 512, false); app.setTargetFrameRate(60); app.start();
} } |
|
|
|
|
|
27
|
Game Development / Newbie & Debugging Questions / Re: Slick2d Renders ontop of itself
|
on: 2012-12-03 15:10:43
|
|
The render-method is meant to create an image, of the images you put inthere like i've done :-) As for that, i'm pretty sure it's right :-D
Edit: The problem is, when a play is in the PlayList, it doesn't remove the old one from the screen when he gets a new position. So every time the PlayerList is refreshed, the old one is still hanging on the image :-(
|
|
|
|
|
28
|
Game Development / Newbie & Debugging Questions / Slick2d Renders ontop of itself
|
on: 2012-12-03 14:34:56
|
I have a gameserver that keeps transferring players and their positions to the clients (every half a second). The client is running Slick2d. The problem is, it is rendering "on top" of itself, which is definitely not intended. The framerate keeps dropping, and texts gets more and more blurry. Here's some screenshots. Right when the client opens:  After like half a minute:  The render method: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public void render(GameContainer gc, Graphics g) throws SlickException { g.drawImage(board.getBackground(), 0, 0); for (int i = 0; i < otherPlayers.size(); i++) { Player newPlayer = otherPlayers.get(i);
g.drawImage(new Image(newPlayer.getFigure()), newPlayer.getX() - 30, newPlayer.getY() - 53); g.setColor(Color.white); g.drawString(newPlayer.getName(), newPlayer.getX() - 18, newPlayer.getY() + 17); } } |
|
|
|
|
|
29
|
Game Development / Newbie & Debugging Questions / Re: Kryonet - Passing players
|
on: 2012-12-03 11:32:51
|
That's what i'm doing already, and that's what's causing the error. Packet class: 1 2 3
| static public class PlayerList { public ArrayList<Player> playerList; } |
Server sending the packet: 1 2 3
| PlayerList toClient = new PlayerList(); toClient.playerList = playerList; server.sendToAllTCP(toClient); |
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Kryonet - Passing players
|
on: 2012-12-03 11:21:29
|
Hello! I have an ArrayList<Player> on my gameserver. I need to transfer this to all clients, to show the players and set their locations. However, as far as i've been able to read, Kryonet doesn't accept objects with constructors (Player obviously have that) so i can't just send the ArrayList<Player>. How can i get the ArrayList to the clients? :-) Trying just to pass it with the constructor gives this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Exception in thread "Client" com.esotericsoftware.kryonet.KryoNetException: Error during deserialization. at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:141) at com.esotericsoftware.kryonet.Client.update(Client.java:239) at com.esotericsoftware.kryonet.Client.run(Client.java:317) at java.lang.Thread.run(Thread.java:680) Caused by: com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): NFT.Player Serialization trace: playerList (NFT.Network$PlayerList) at com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1048) at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1060) at com.esotericsoftware.kryo.serializers.FieldSerializer.create(FieldSerializer.java:228) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:217) at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:735) at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:109) at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:18) at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:654) at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:605) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:221) at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:735) at com.esotericsoftware.kryonet.KryoSerialization.read(KryoSerialization.java:57) at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:139) ... 3 more |
And my Player class: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public class Player { private int playerId; private String name; private int playerX; private int playerY; private String figure; public Player(String name, int positionX, int positionY, int playerId) { this.name = name; this.playerX = positionX; this.playerY = positionY; figure = "NFT/player.png"; } public int getX() { return playerX; } public int getY() { return playerY; } public void setPosition(int x, int y) { this.playerX = x; this.playerY = y; } public String getFigure() { return figure; } public int getId() { return playerId; } public String getName() { return this.name; } public void setRandomPosition() { int randomX = 5 + (int)(Math.random() * ((768 - 5) + 1)); int randomY = 5 + (int)(Math.random() * ((512 - 5) + 1)); int newX = Math.round(randomX / 50) * 50 + 25; int newY = Math.round(randomY / 50) * 50 + 25;
int tileCoordY = newY - (newY % 50); int finalX; int finalY = newY; if (tileCoordY % 2 == 1) { finalX = newX + 25; } else { finalX = newX; } setPosition(finalX, finalY); } } |
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|