Jump to content

  • Log In with Google      Sign In   
  • Create Account

LeDerpish

Member Since 22 Mar 2012
Offline Last Active Apr 25 2014 04:57 AM

Posts I've Made

In Topic: Slow mouse position

09 July 2012 - 10:36 AM

Oh nvm, I just realized that letting the thread sleep for 20 ms helped... Thank you and sorry for bothering!

In Topic: Slow mouse position

09 July 2012 - 10:29 AM

Here is the full code for the "game":

[source lang="java"]import java.awt.Color;import java.awt.Graphics;import java.awt.GraphicsDevice;import java.awt.GraphicsEnvironment;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.awt.image.BufferStrategy;import javax.swing.JFrame;public class GameFrame extends JFrame { private static final long serialVersionUID = 1L; private GraphicsEnvironment ge; private GraphicsDevice gd; private BufferStrategy buffer; private boolean running; //Set the game to full screen and start it public static void main(String[] args) { GameFrame game = new GameFrame(); game.setFullScreen(); game.start(); } //Constructor public GameFrame() { super("Game Test"); setDefaultCloseOperation(EXIT_ON_CLOSE); ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getDefaultScreenDevice(); //the game will stop running if escape is pressed addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent event) { if(event.getKeyCode() == KeyEvent.VK_ESCAPE) { running = false; } } }); } //Make the game full screen and create a buffer strategy public void setFullScreen() { setUndecorated(true); setIgnoreRepaint(true); setResizable(false); gd.setFullScreenWindow(this); createBufferStrategy(2); buffer = getBufferStrategy(); } //Main loop is here public void start() { Graphics g = null; running = true; while(running) { try { g = buffer.getDrawGraphics(); g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(Color.RED); g.fillRect(getMousePosition().x, getMousePosition().y, 20, 20); if(!buffer.contentsLost()) { buffer.show(); } } finally { if(g != null) { g.dispose(); } } } System.exit(0); }}[/source]

lwjgl and Slick2D is programmed in Java, right? So there has to be some way to do it properly.

In Topic: Display mode advice needed

07 April 2012 - 02:01 PM

Thank you very much! Will try to implement this now. :P

In Topic: Display mode advice needed

07 April 2012 - 10:35 AM

assuming you've coded the rest of your program to be resolution-agnostic (i.e. working in normalized coordinates) it will work flawlessly.

But how do I do that? :o

In Topic: Display mode advice needed

06 April 2012 - 11:25 AM

And when the mode is changed you need to make sure your graphics code is flexible when it comes to resolution changes, so you can just change two variables (width and height) and update your graphics states. Normally game logic should not change, since you're normalizing coordinates, right? (between (-1, -1) and (+1, +1) regardless of the resolution).

Any idea on how to do this? Cuz as I said, I tried to do this by drawing everything to a buffered image which I then resized, but I get problems with mouse inputs then...

PARTNERS