Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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] 2
1  Game Development / Newbie & Debugging Questions / Re: how do you guys make in 2d games message dialog box like joptionpane on: 2013-11-22 10:34:09
Honestly, I just made it. Smiley
2  Game Development / Newbie & Debugging Questions / Re: how do you guys make in 2d games message dialog box like joptionpane on: 2013-11-22 09:53:35
Alright, that class is comes from libgdx http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Dialog.html
However, did anyone ever make himself a class Dialog ?
3  Game Development / Newbie & Debugging Questions / how do you guys make in 2d games message dialog box like joptionpane on: 2013-11-22 00:53:46
I'm curious, but how do you guys make dialog box (like JOptionPane) in 2d games for example in slick2d ?
I would like to have confirm and message dialog, to pop up on some of the actions.
Are there any examples ?
4  Game Development / Newbie & Debugging Questions / Re: Checking If One List Contains Another on: 2013-11-21 23:25:08
Nvm, found the error...
class java.lang.String / class java.lang.Integer
5  Game Development / Newbie & Debugging Questions / Checking If One List Contains Another on: 2013-11-21 23:02:11
So I have to check if settings have been changed. However, I'm getting strange result.
Even though the values are the same, it returns true, instead of false.

Result:
1  
2  
3  
4  
5  
Old settings: [800, 600, false, true, true, 2.3]
Current settings: [800, 600, false, true, true, 2.3]
Old list element at 0 is 800
Current list element at 0 is 800
TRUE!


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  
    public static boolean settingsChanged() {
        System.out.println("Old settings: " + oldSettingsList);
        System.out.println("Current settings: " + getCurrentSettingsList());
       
        List oldList = oldSettingsList;
        List currentList = getCurrentSettingsList();
        int maxLen = Math.max(oldList.size(), currentList.size());
       
        for (int i = 0; i < maxLen; i++) {
            Object obj1 = oldList.get(i);
            Object obj2 = currentList.get(i);
            System.out.println("Old list element at " + i + " is " + obj1);
            System.out.println("Current list element at " + i + " is " + obj2);
           
            if (!obj1.equals(obj2)) {
                System.out.println("TRUE!");
                return true;
            }
        }
        System.out.println("FALSE!");
        return false;
    }
   
    public static List getOldSettingsList() {
        return oldSettingsList;
    }
   
    public static List getCurrentSettingsList() {
        List newSettingsList = new ArrayList();
       
        newSettingsList.add(video.getWidth());
        newSettingsList.add(video.getHeight());
        newSettingsList.add(video.isFullScreen());
        newSettingsList.add(video.isFps());
        newSettingsList.add(sound.isSound());
        newSettingsList.add(sound.getVolume());
       
        return newSettingsList;
    }
6  Game Development / Newbie & Debugging Questions / JOptionPane possible in slick2d ? on: 2013-11-03 12:25:48
If so, should I call it inside update or render method ?
7  Game Development / Newbie & Debugging Questions / Re: Button Functionality (over, pressed and down) on: 2013-10-26 11:55:50
Alright, thank you guys for your time. I will see what I can do later with your code examples. Right now I'm not really focused into this.. and I have to go now do some other work.
8  Game Development / Newbie & Debugging Questions / Re: Button Functionality (over, pressed and down) on: 2013-10-26 11:46:32
@OP Try this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
boolean buttonDown;
    public boolean isActionPerformed(Input input, int mx, int my) throws SlickException {
        if (buttonContains(mx, my)) {
            if (buttonPressed(input)) {
                buttonDown = true;
            }
            else if (buttonReleased(input) && buttonDown) {
                 buttonDown = false;
                 runActionOrDoWhateverHere();
            }
        }
        return false;
    }



I don't have buttonReleased method, what do you think it should contain ?
9  Game Development / Newbie & Debugging Questions / Re: Button Functionality (over, pressed and down) on: 2013-10-26 11:43:51
This is a function that I created few days ago, what it does is, if is pressed once, execute.. but after that press, if a button is not released, and is last for 1s, then execute down method, which spams.. Tbh, I don't like way of doing this.. So that's what I want now to short code into actionPerform

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  
    public String getButtonExecutionInterval(GameContainer container, Input input, int delta, int mx, int my) throws SlickException {
        if (this.buttonContains(mx, my)) {
            if (this.buttonPressed(input)) {
                this.invoke = false;
                this.lastInvoke = container.getTime();

                return ONCE;
            }
            if (this.pressedTime < this.timeDuration && !this.buttonDown(input)) {
                this.pressedTime = this.timeDuration;
            }
            if (this.lastInvoke + 1000 < container.getTime()) {
                this.invoke = true;
            }
            if (this.buttonDown(input) && this.invoke) {
                this.pressedTime -= delta;
                if (this.pressedTime <= 0 && this.buttonDown(input)) {
                    this.pressedTime = this.timeDuration;

                    return REPEATEDLY;
                }
            }
        }
        return NEVER;
    }
10  Game Development / Newbie & Debugging Questions / Re: Button Functionality (over, pressed and down) on: 2013-10-26 11:32:37
Alright, but this is executing multiple times when mouse is down, what about mouse pressed?
I can't figure out where to place, since both pressed & down methods have the same action... In which case, pressed does only 1 click, and down does like 5-6 clicks??  That's what confuses me..
11  Game Development / Newbie & Debugging Questions / Re: Button Functionality (over, pressed and down) on: 2013-10-26 11:19:59
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
    boolean buttonDown;
    public boolean isActionPerformed(Input input, int mx, int my) throws SlickException {
        if (buttonContains(mx, my)) {
            if (buttonPressed(input)) {
                buttonDown = true;
            }
            if (buttonDown(input)) {
                buttonDown = false;
            }
        }
        return false;
    }


And.. ?
12  Game Development / Newbie & Debugging Questions / Re: Button Functionality (over, pressed and down) on: 2013-10-26 11:08:49
Well, there is no isMouseReleased method inside Input class...
13  Game Development / Newbie & Debugging Questions / Re: Button Functionality (over, pressed and down) on: 2013-10-26 10:34:39
I don't need code, I need help, on how to create it.. like pseudo code or explain how it works?
14  Game Development / Newbie & Debugging Questions / Button Functionality (over, pressed and down) on: 2013-10-26 09:47:48
I'm creating a simple button class, with Slick2D library.
However, I have a problem, on how to create a buttonReleased function.
So problem is, I click the button, and it already executes, with out releasing a mouse click.
What I want to achieve, is, I click the button, but execute only if a mouse click is released inside a button area.

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  
    public boolean isActionPerformed(Input input, int mx, int my) throws SlickException {
        if (buttonContains(mx, my)) {
            if (buttonPressed(input)) {
                return true;
            }
            if (buttonDown(input)) {
            }
        }
        return false;
    }
   
    public boolean buttonContains(int mx, int my) throws SlickException {
        if ((mx > minX && mx < maxX) && (my > minY && my < maxY)) {
            buttonState = ButtonState.Over;
            return true;
        }
        buttonState = ButtonState.Normal;
        return false;
    }
   
    public boolean buttonPressed(Input input) throws SlickException {
        if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
            return true;
        }
        return false;
    }

    public boolean buttonDown(Input input) throws SlickException {
        if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
            buttonState = ButtonState.Down;
            return true;
        }
        return false;
    }
15  Game Development / Newbie & Debugging Questions / Re: i don't get scalable objects on: 2013-10-19 10:15:42
Has anyone worked with this class so far?
16  Game Development / Newbie & Debugging Questions / Re: i don't get scalable objects on: 2013-10-18 20:18:23
Well, I tried that already, but nothing really changes, and I should keep it true, if I want objects to scale.
Alright, so this is how state looks by default:
1  
2  
3  
4  
5  
appGameContainer = new AppGameContainer(
     new ScalableGame(new AppStateController(), Settings.video.getWidth(), Settings.video.getHeight(), true)
);
appGameContainer.setDisplayMode(Settings.video.getWidth(), Settings.video.getHeight(), Settings.video.isFullScreen());
appGameContainer.start();



If I assign to width/height +100, ScalableGame constructor:
1  
2  
3  
4  
5  
appGameContainer = new AppGameContainer(
     new ScalableGame(new AppStateController(), Settings.video.getWidth(), Settings.video.getHeight(), true)
);
appGameContainer.setDisplayMode(Settings.video.getWidth(), Settings.video.getHeight(), Settings.video.isFullScreen());
appGameContainer.start();


If I assign to width/height +100, to display:
1  
2  
3  
4  
5  
appGameContainer = new AppGameContainer(
     new ScalableGame(new AppStateController(), Settings.video.getWidth(), Settings.video.getHeight(), true)
);
appGameContainer.setDisplayMode(Settings.video.getWidth() + 100, Settings.video.getHeight() + 100, Settings.video.isFullScreen());
appGameContainer.start();



So, even if I change resolution to 800/600 or 1000/800, both image and shape are always the same size..
17  Game Development / Newbie & Debugging Questions / Re: i don't get scalable objects on: 2013-10-18 16:16:10
Yes! However, problem is, UI components doesn't change size to a little bit bigger, it's always same.. i'm using this resolution types
{
            {800, 600},
            {1000, 700},
            {1200, 800},
            {1400, 900}
 };
18  Game Development / Newbie & Debugging Questions / i don't get scalable objects on: 2013-10-18 15:52:39
I'm using class ScalableGame class, to get scalable objects with screen size, but nothing changes.. So, what I'm doing wrong?

1  
2  
3  
4  
5  
6  
        
appGameContainer = new AppGameContainer(
     new ScalableGame(new AppStateController(), Settings.video.getWidth(), Settings.video.getHeight(), true)
);
appGameContainer.setDisplayMode(Settings.video.getWidth(), Settings.video.getHeight(), Settings.video.isFullScreen());
appGameContainer.start();


19  Java Game APIs & Engines / Java 2D / Re: scaling graphic objects in slick2d on: 2013-10-18 15:07:35
Ok, seems pretty easy, I just need to call instance, inside my main method.. Btw, why are the objects so blurry ? Is there any way to fix it maybe, or that's just how it is ?
20  Java Game APIs & Engines / Java 2D / Re: scaling graphic objects in slick2d on: 2013-10-18 13:29:29
Thanks for this, but is there any example on how to use this?
Also could someone give more solutions?
21  Java Game APIs & Engines / Java 2D / scaling graphic objects in slick2d on: 2013-10-18 12:07:38
How to  scale components on the frame by resolution? So, whenever I change screen size, for example, from 600/400, up to 1200/800, images, graphics, objects are also larger size?  
- I've found a method inside Graphic class, called, g.scale(sx,sy); , but I'm not really sure what type of x,y should I pass? Also, it seems to be really useful method, which will literally do all the job, matters to scaling, if im not wrong?
22  Game Development / Newbie & Debugging Questions / Re: Button class, image or graphics? on: 2013-10-10 10:42:40
If you're that worried about memory usage, use a texture atlas.
Nah, I was just curious.. Cheesy
Thank you guys on replys.
23  Game Development / Newbie & Debugging Questions / Button class, image or graphics? on: 2013-10-09 17:41:32
I'm creating a button class in Slick2D library for game development. So I want to instead of using three images for a button like contains, pressed and down, to use graphics to draw a rectangle and add to it many other graphic features, and what takes more memory ?
24  Game Development / Newbie & Debugging Questions / Re: What's the best way to go about game states? on: 2013-10-06 10:11:44
That's what I thought about...
25  Game Development / Newbie & Debugging Questions / Re: What's the best way to go about game states? on: 2013-10-06 09:39:34
I did not understand you, why do you hate to be "that guy", what do you mean ?  What's so bad about "State Design Pattern" ?

If you don't like text tutorials, you can watch as well design pattern video tutorials on Derek Banas youtube channel. Here's the tutorial link to "State Design Pattern" http://www.youtube.com/watch?v=MGEx35FjBuo
26  Game Development / Newbie & Debugging Questions / slick2d UnicodeFont dropes frames on: 2013-10-05 12:24:38
I was creating a showMessageDialog, just like component from `JOptionPane.showMessageDialog` and I tried to use UnicodeFont to compute total width of the string, so that I can check if the String line goes above max width of the panel. However, my frames have dropped from 2000 fps on to 30. I thought the reason could be UnicodeFont, I commented try/catch block where I create font, and frames are back to normal. So what do you think could be the problem, font or list of the methods I call to make an effects to a font instance?


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  
        public static void showMessageDialog(GameContainer container, Graphics g, String title, String text) throws SlickException {
    UnicodeFont textFont;
            try {
                textFont = new UnicodeFont("res/font/CharlemagneStd-Bold.ttf", 14, false, false);
                textFont.addAsciiGlyphs();
                textFont.getEffects().add(new ColorEffect());
                textFont.loadGlyphs();
            } catch (SlickException ex) {
                System.err.println("Font error...");
                return;
            }
            g.setFont(textFont);
   
            // title, drawLine...
   
            // render text
           float textX = panelMinX + panelInPaddingLeft + strFixHorizontalPadding;
            float textY = Math.max(lineY1, lineY2) + panelInPaddingTop;
   
            String[] sentence = text.split(" ");
            ArrayList<String> strLineList = new ArrayList<>();
            String strLine = "";
            float currentTextWidth;
            float maxLineWidth = (panelMaxX - panelMinX) - (panelInPaddingLeft + panelInPaddingRight + strFixHorizontalPadding);
           
            for (int word = 0; word < sentence.length; word++) {
                currentTextWidth = textFont.getWidth(strLine) + textFont.getWidth(sentence[word]);
               
                if (currentTextWidth > maxLineWidth) {
                    strLine = strLine + "\n";
                    strLineList.add(strLine);
                    strLine = "";
                    word--;
                } else {
                    strLine = strLine + sentence[word] + " ";
                }
                if (word == sentence.length - 1) {
                    strLineList.add(strLine);
                    strLine = "";
                }
            }
            for (String line : strLineList) {
                strLine = strLine + line;
            }
            g.setColor(Color.white);
            g.drawString(strLine, textX, textY);
    }


p.s. If there's solution for getting string width/height, or some other way of coding font to instantiation constructor with calling width/height method and ofc avoiding this frames drop down ..
27  Game Development / Newbie & Debugging Questions / Re: is it possible to manipulate with BufferedReader and BufferedWriter on: 2013-09-30 13:39:33
Nope, it's not going to be large.

http://technojeeves.com/joomla/index.php/free/74-string-list
And yes, you got a point. Definitely I will do it that way.
28  Game Development / Newbie & Debugging Questions / Re: is it possible to manipulate with BufferedReader and BufferedWriter on: 2013-09-30 11:27:00
Quote
I want to search for a value that is changed and to replace it with a new one.

As I say above.
29  Game Development / Newbie & Debugging Questions / is it possible to manipulate with BufferedReader and BufferedWriter on: 2013-09-30 11:17:41
By this I mean that we have control over BuffererReader, at what line he should stop reading and at which he should continue.

With a scanner, I could search for a specified title, and from that line to start reading values, all until to the line "end".

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  
public void load(String filePath) {
    boolean isVideo = false;
    String readLine;

    verifyFilePath(filePath);

    while (loadInput.hasNext()) {
        readLine = loadInput.next();
        if (readLine.equalsIgnoreCase("video")) {
            isVideo = true;
            break;
        }
    }

    while (isVideo && loadInput.hasNext()) {
        readLine = loadInput.next();
        if (readLine.equalsIgnoreCase("end")) {
            break;
        }
        String[] line = readLine.split("=");

        String key = line[0];
        String value = line[1];

        switch (key) {
            case "width":
                frameSize.setWidth(Integer.parseInt(value));
                break;
            case "height":
                frameSize.setHeight(Integer.parseInt(value));
                break;
            case "fullscreen":
                fullScreen.setFullScreen(Boolean.parseBoolean(value));
                break;
            case "fps":
                fps.setFps(Boolean.parseBoolean(value));
                break;
            default:
                System.err.println("Unknown video key: " + key);
                break;
        }
    }
    loadInput.close();
}


However, my problem is a save method. I again want to achieve same point, but this time I want to search for a value that is changed and to replace it with a new one.
I've looked into javadoc, and found some mark method, but didn't work.

And what this code below does right now, iBufferedReader in the first while loop searches for "video" title, then goes all to the last line, and then on that last line he start appending this temp strings, which is not the way I want.

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  
public void save() {
        BufferedReader bfReader;
        BufferedWriter bfWriter;
       
        try {
            bfReader = new BufferedReader(new FileReader(new File(filePath)));
            bfWriter = new BufferedWriter(new FileWriter(new File(filePath), true));

            boolean isVideo = false;
            int currentIndex = 0;
            String currentLine;
           
            while (((currentLine = bfReader.readLine()) != null) && !isVideo) {
                if (currentLine.equalsIgnoreCase("video")) {
                    bfReader.mark(currentIndex); // marks current position
                   isVideo = true;
                    break;
                }
                currentIndex++;
            }
           
            if (bfReader.markSupported()) {
                System.out.println("Mark supported... reset!");
                bfReader.reset();
            }
           
            while (isVideo && ((currentLine = bfReader.readLine()) != null)) {
                if (currentLine.equalsIgnoreCase("end")) {
                    break;
                }
               
                String[] line = currentLine.split("=");

                String key = line[0];
                String value = line[1];

                switch (key) {
                    case "width":
                        if (!value.equals(String.valueOf(frameSize.getWidth()))) {
                            // then change value
                           bfWriter.append("\t NEW WIDTH");
                        }
                        break;
                    case "height":
                        if (!value.equals(String.valueOf(frameSize.getHeight()))) {
                            // then change value
                           bfWriter.append("\t NEW HEIGHT");
                        }
                        break;
                    case "fullscreen":
                        if (!value.equals(String.valueOf(fullScreen.isFullScreen()))) {
                            // then change value
                           bfWriter.append("\t FULL SCREEN");
                        }
                        break;
                    case "fps":
                        if (!value.equals(String.valueOf(fps.isFps()))) {
                            // then change value
                           bfWriter.append("\t FPS");
                        }
                        break;
                    default:
                        System.err.println("Unknown video key: " + key);
                        break;
                }
            }
           
            bfWriter.close();
            bfReader.close();
        } catch (IOException ex) {
            System.err.println("An exception has occurred during data saving.");
            return;
        }
        System.out.println("Settings has been successfully saved!");
    }


So finally, flow control and replace value are the problems.
30  Java Game APIs & Engines / Java 2D / Re: Design Pattern For Game Settings on: 2013-09-27 08:20:32
First of all, thank you guys on quick and constructive replies.

Quote
Patterns are used to prevent creating tightly coupled and difficult to maintain code.
I want to point this out,

However,
Quote
You shouldn't use pattern if you can't (yourself) recognize a pattern that would fit your problem.
I'm not mean to be rude, but I have already first suggested above, in order to get an opinions about it.

However, I've already watched like 2x design pattern tutorials, and I really really got seek of using duplicate codes and many arrays.. I haven't ever used them before in a serious projects, but that's the reason now I want to. I would like to recommend Derek Banas Design Pattern Tutorials http://www.youtube.com/watch?v=vNHpsC5ng_E&list=PLF206E906175C7E07.

Also, thank you SHC, I will take a look at that.
Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (43 views)
2014-09-23 14:38:19

radar3301 (25 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (37 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!