Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (525)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: BufferStrategy - it doesn't update graphics on: 2014-02-10 00:55:59
Thanks, looks pretty similar to my approach, but I think that what does the trick is
 
1  
2  
    g.clearRect(0, 0, 400, 400);
      g.setColor(Color.blue);


so, Solved!

2  Game Development / Newbie & Debugging Questions / Re: BufferStrategy - it doesn't update graphics on: 2014-02-10 00:02:11
Quote
First, although I don't think it should make a difference (could be wrong, it's been awhile), I would dispose the graphics after backbuffer.show(), as per http://docs.oracle.com/javase/tutorial/extra/fullscreen/bufferstrategy.html

this link dispose the graphics before showing them from backbuffer

Quote
Also, instead of setting the current color to the background color and fillRect, you can simply: clearRect()

good tip
3  Game Development / Newbie & Debugging Questions / Re: BufferStrategy - it doesn't update graphics on: 2014-02-09 23:56:50
the only way I actually managed to "correctly" update the drawing, is by drawing something over it, using:

1  
2  
graphics.setColor (getBackground ());
graphics.fillRect (0, 0, this.getSize().width, this.getSize().height);


but, isn't
1  
graphics.dispose();
supposed to clear the graphics and let space for the incoming?

thanks

4  Game Development / Newbie & Debugging Questions / BufferStrategy - it doesn't update graphics on: 2014-02-09 23:47:53
Hi, I'm having problems with BufferStrategy... for some reason I can't manage to update the graphics in it:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public void Draw()
    {
        backbuffer = this.getBufferStrategy();
       
        do
        {
            try{
                    graphics = backbuffer.getDrawGraphics();
                    DrawAll(); //this draws thing on "graphics"
            }
            finally
            {
                graphics.dispose();
            }

            backbuffer.show();
            Toolkit.getDefaultToolkit().sync();
        } while (backbuffer.contentsLost());
    }


It is necessary to say that I always call this method? but for some reason I can't see my ... new graphics?
If you need more details, just tell me.

Thanks.
5  Game Development / Newbie & Debugging Questions / Re: mouseMoved is never called on: 2014-02-07 02:59:31
Ok, so I basically redesigned the hierarchy of classes.
Now is like so:

Game -> Drawer (JFrame) -> Listener

Game is a class, which instantiates a Drawer (JFrame), and this contains the Listener.
Also, I'm implementing BufferStrategy on Drawer.

Now it Works perfectly, using the same help you gave me =).

Thanks!
6  Game Development / Newbie & Debugging Questions / Re: mouseMoved is never called on: 2014-02-02 01:29:31
Ok, I've taken your advice into having the Game extends from JPanel. But what if I want the paint methods to be in another class? that's why I created a Drawer. what do you recommend here? Drawer should extend from what??

I'm implementing BufferStrategy, as son as I have it working I'm going to post here with results.

thanks.
7  Game Development / Newbie & Debugging Questions / Re: mouseMoved is never called on: 2014-02-02 00:18:27
Ok, now it Works. I added Agros' code wrong before.
Now I'm having another problem (I always have problems with two things: eventListeners and Backbuffers)

I'm implementing backbuffer on a Drawer, like 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  
public class Drawer extends Applet {
   
    Image backbuffer;
    Graphics graphics;
    Map map;
   
    boolean firstTime;
   
    public Drawer(Map mapCopy)
    {
        setVisible(true);
        setBounds(0,0,300,300);
        map = mapCopy;
        firstTime = true;
    }

    public void Draw()
    {
        //draw lots of things into graphics        
        repaint();
       
    }
   
    public void update( Graphics g )
    {
        g.drawImage( backbuffer, 0, 0, this );
    }

    public void paint( Graphics g )
    {  
       if(firstTime)
       {
            backbuffer = createImage(getSize().width,getSize().height);
            graphics = backbuffer.getGraphics();
       }
       update( g );
    }
}


I've read tons of examples of how to implement it, but all sites use different methods, and I just tried to use the most convenient.
The problem is simple: when Draw() method is called, graphics returns null, and doesn't let me draw anything into it.

Thanks.
8  Game Development / Newbie & Debugging Questions / Re: mouseMoved is never called on: 2014-02-01 23:54:09
I'm surprised! it didn't work either!
I also found that if I put breakpoint on listener and I go into debug mode... the code Works good.

Any other ideas?

thanks.
9  Game Development / Newbie & Debugging Questions / Re: mouseMoved is never called on: 2014-02-01 23:34:36
Gosh, that's a fast reply!!
Already tried that, but didn't work.

Could be it that the Listener never obtains focus? Will help if I tell you that the game calls repaints functions?
10  Game Development / Newbie & Debugging Questions / mouseMoved is never called on: 2014-02-01 23:30:27
Hi everyone.
The problem is simple: the mouseMoved event is never called.
Let's see the code.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class Window extends javax.swing.JFrame {

    public Window() {
        initComponents();
        setVisible(true);
        setResizable(false);
        jPanel1.setVisible(true);
        jPanel1.setBounds(0,0,300,300);
       
        Game g = new Game();
        jPanel1.add(g);
    }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public Game()
    {
        setVisible(true);
        setBounds(0,0,300,300);
        map = new Map();
        drawer = new Drawer(map);
        listener = new Listener(map);
        t = new Thread(this);
       
        this.add(drawer);
        addMouseListener(listener);
        t.start();
    }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public class Listener extends MouseAdapter{

    int mouseX, mouseY;
    Map map;
    public Listener(Map copyMap)
    {
        mouseX = 0;
        mouseY = 0;
        map = copyMap;  
    }
   
    @Override
    public synchronized void mouseMoved(MouseEvent evt)
    {
        GetMouseCords(evt);
        ShouldMoveView();
        System.out.println("f**k");
    }


Got any tips? thanks!
11  Game Development / Networking & Multiplayer / Re: Question on lockstep model on a RTS on: 2013-01-12 14:06:31
no possible solution?
am I doing something obviously wrong?
12  Game Development / Networking & Multiplayer / Re: Question on lockstep model on a RTS on: 2013-01-07 00:20:27
I give up, it works slow, and I don't understand why, I mean, when I make a localhost test, it works smoothly, but when trying with another pc over lan, it lags a lot...

here is the code:

set_tcp_nodelay is done outside...

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  
private void ReceiveData()
    {

        try{
                if(whoisthis == 1) //for server
                {
                    indata1 = new ObjectInputStream(sk.getInputStream());
                   
                    info_other1 = (Information) indata1.readObject();
                    ProcessInformation(info_other1); //process client info
                   
                    ProcessInformation(info); //process own info
                   
                   
                }
                else //for client
                {
                    indata1 = new ObjectInputStream(sk.getInputStream());
                    indata2 = new ObjectInputStream(sk.getInputStream());
                   
                    info_other1 = (Information) indata1.readObject();
                    info_other2 = (Information) indata2.readObject();
                   
                    ProcessInformation(info_other1);
                    ProcessInformation(info_other2);
                   
                   
                }
               }catch(IOException ioe){} catch(ClassNotFoundException css){System.out.println("nothing to do here");}
   
    }


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  
private void SendData()
    {
       
         
        try{

              if(whoisthis == 2) //this is client
              {
                outdata1 = new ObjectOutputStream(sk.getOutputStream());
               
                outdata1.writeObject(info);
                info.CleanInformation();
                   
                info_other1.CleanInformation();
                info_other2.CleanInformation();
               
               
              }
              else //this is server
              {
                  outdata1 = new ObjectOutputStream(sk.getOutputStream());
                  outdata2 = new ObjectOutputStream(sk.getOutputStream());
                 
                  outdata1.writeObject(info); //send server info
                 
                  info.CleanInformation();
                   
                   outdata2.writeObject(info_other1); //send client info
                  info_other1.CleanInformation();
                 
              }

             
            }catch(IOException ioe){}
    }

 
class Information contains a matrix of 6x5 integers.

so, what am I doing wrong here?

thanks for your help.

bye

PD: I read the two generals problem...just...wow..
13  Game Development / Networking & Multiplayer / Re: Question on lockstep model on a RTS on: 2012-12-19 01:40:53
there's a lot of lag, I mean, the game works at an "good" speed for like 2 seconds and then it lags for some milliseconds...like so...
14  Game Development / Networking & Multiplayer / Re: Question on lockstep model on a RTS on: 2012-12-19 01:16:30
it doesn't do just 6 updates per frame, it does all the necessary updates per frame, the only thing is that it only sends 6 commands per frame because is the maximum number of commands a player can make at the same time (for example, you can select 6 units at the moment, and send them to do something)

I added the tcpnodelayoption and works faster, even so, is still very slow...
I'm going to explain in detail what I'm doing so you can help me...

every time the client gives a unit a new order, that order is stored on the Information object.

on the principal thread, client and server are always sending and receiving data, so, in this case, server receives this information object, processes it, and returns it back to the client...

this happens every step, is this causing the game to be slow? it's very frustating you know...
15  Game Development / Networking & Multiplayer / Re: Question on lockstep model on a RTS on: 2012-12-18 15:36:31
So, I have another question!
I want to show you what's the client sending to the server and viceversa:

the client sends an object called information, with a matrix of 6*5.
6 being the maximum number of possible orders in a single moment, and 5 representing
(0) action
(1) id
(2) row
(3) column
(4) step

let's say for example, that server approves a move of the client, it will be like this:

(0) 1 = move
(1) 32
place is going to move:
(2) 4
(3) 5
execute this on this step:
(4) 12


problem is, even with this optimization, I mean, I trying to send as least information of a command possible...well
the game is still is low, should I suppose that the problem is somewhere else?

thanks!!

bye!!
16  Game Development / Networking & Multiplayer / Re: Question on lockstep model on a RTS on: 2012-12-14 17:41:42
excellent, thanks for your advice!
17  Game Development / Networking & Multiplayer / Re: Question on lockstep model on a RTS on: 2012-12-14 15:40:25
B is the server and A is the client, in this case.

the thing is, how does the server knows that the client received the approval?
if the client says, "hey, I received the approval, I'm going to move on next turn!" the how does the client know that
the server received this?

In a short term, If a pack of information is lost, then the game will be desync and I have no way to test that...
18  Game Development / Networking & Multiplayer / Question on lockstep model on a RTS on: 2012-12-14 15:24:50
Hi! the question is simple.
Considering the lockstep model, let's suppose I have user A and B.

A wants to move a unit, so it sends the command to B
B receives the command and tells A that they will execute the command at step 5
A receives the message

the problem is, from the point of view of B, how do B know that A received the message? ok, I can say that A tells B that it received the message succesfully and the will move at step 5...but again....now how do A know that B received this last message?

see my point here? I hope I made myself clear.

thanks, bye!
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (67 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (12 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (29 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (53 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!