Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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: problems with animation on: 2012-01-27 15:02:07
It seems I figured it out.

As found in getScaledInstance documentation: "...The new Image object may be loaded asynchronously even if the original source image has already been loaded completely..."

So I should use ImageIcon again when scaling my paddle. And code may look like that:

1  
2  
3  
4  
                    for (int i = 0; i < NARROWER_FRAMES; i++) {
                        ImageIcon ii = new ImageIcon (iid.getImage().getScaledInstance(w - sizechange * (i + 1), H, 0));
                        narrower[i] = ii.getImage();
                    }


Now it's smooth like before Smiley
2  Game Development / Newbie & Debugging Questions / Re: problems with animation on: 2012-01-26 15:03:50
I see that you regenerate the animation array every single time you call Wider(). It is best to generate these arrays when the class is first initialized, so then all you have to do is modify the "currentFrame" variables.

Actually moving this image generation to constructor didnt help. And as I understand shouldnt keeping in mind 2 FPS game speed for generation 10 images of size 80x15 pixels Smiley

Started to debug and noticed, that my Draw method was called more often than game loop. Passing null as image observer stopped that.

Also I noticed, that image is not drawn for the first time! That probably caused flickering! So when I in my Draw method at the beginnig drew all images from array, images from this array were drawn correctly without flashing (when paddle was getting wider).
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
    public void Draw (Graphics g, JPanel p) {
        for (int i = 0; i < WIDER_FRAMES; i++) {
           g.drawImage(wider[i], 60, STARTY - 20 * (i + 2), null);
        }
        switch (state) {

            case GET_NARROWER:
                g.drawImage(narrower[narrowerframe], x, y, null);
                break;
            case GET_WIDER:
                g.drawImage(wider[widerframe], x, y, null);
                 break;
            default:
                g.drawImage(paddle, x, y, null);
                break;
        }
    }


Without this loop in the beginning and passing null as image observer I saw no paddle image at all when paddle was getting wider. Also putting same drawImage twice was not helping:

1  
2  
3  
4  
            case GET_WIDER:
                g.drawImage(wider[widerframe], x, y, null);
                g.drawImage(wider[widerframe], x, y, null);
                break;


I see, that I dont understand what happening Smiley But maybe somebody could explain me?

My thoughts are like:
1. I am using wrong game loop (posted in first message).
2. I do not handle image drawing correctly.

Which one, or maybe both? Or something else? Where is truth? Smiley
3  Game Development / Newbie & Debugging Questions / Re: problems with animation on: 2012-01-25 19:03:20
Delayed game loop to 2 FPS and removed background - paddle still flickers on resize but not every frame (randomly actually). When moving paddle - everything ok, like before.
4  Game Development / Newbie & Debugging Questions / Re: problems with animation on: 2012-01-25 17:10:22
To add more knowthebetter suggestions Wink

Try not to write the code "propperly" as learned in programming class.
Messie, linear code can help to get things done, and keep motivation up.

So dont structure your code too much yet.

Aha thanks Smiley You think this will help me to solve paddle flashing on resize problem? Wink
5  Game Development / Newbie & Debugging Questions / Re: problems with animation on: 2012-01-25 16:56:12
I can't really comment on the update method, but I know one thing: what you're trying to do is interpolating the scale of your paddle from a narrow size to a wider size, and vice-versa.

Instead of playing with state-machines and frames, I would recommend you to have a look to this library (it's not self-advertising, the lib is free, it's just that it could be a nice use-case Grin).

For instance, your Wider() method would be as follows:
1  
2  
3  
4  
5  
    public void Wider () {
        myManager.killTarget(this, SCALE_X);
        Tween.to(this, SCALE_X, 500).target(2).ease(Quart.INOUT).start(myManager);
        Tween.to(this, SCALE_X, 500).target(1).ease(Quart.INOUT).delay(EFFECT_DELAY).start(myManager);
    }


line 1: Stops any running animation affecting the scale of our paddle,
line 2: Animates the scale of the paddle from its current value to twice its size (with a nice "quart" easing) during 500ms,
line 3: Wait for EFFECT_DELAY milliseconds, then animates the scale of the paddle from its current value to its original size (with a nice "quart" easing) during 500ms.

....


Simple enough?

Yep, you're right. And thanks for link. When using library code is simplier, thats true. Library seems really useful. But I've got some goals here:
1. Learn Java actually Smiley
2. Learn and feel (that it is more important for me) graphics programming and it's concepts and capabilities
3. Understand actually what went wrong here, cause till now everything went quite smooth. Smiley
6  Game Development / Newbie & Debugging Questions / Re: problems with animation on: 2012-01-25 16:02:48
Thanks for answering!

Yeah, I forgot to mention that I do use doublebuffering provided by JPanel:

1  
setDoubleBuffered(true);

Maybe these are roots of evil? Smiley

For me it almost always flashes (those few times I think I saw that it didn't flash I can address to my imagination Smiley )

Anyway, here is full Paddle class listing:

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  
public class Paddle {
   
    enum State {NORMAL, WIDE, GET_WIDER, GET_NARROWER};
    State state = State.NORMAL;
   
    public enum Direction {LEFT, RIGHT, NONE};
    int dm = 0, w;
    Direction direction = Direction.NONE;
   
    Image paddle;
   
    ImageIcon iid = new ImageIcon(this.getClass().getResource("paddle.png"));
   
    final int STARTX = 200, STARTY = Board.BOARD_Y_TO - 40, SPEED = 15, SPEEDD = 7, W = 80, H = 15;
    final int XLEFT = BrickBoard.X, XRIGHT = BrickBoard.X + BrickBoard.W;
    final int EFFECT_DELAY = 50, WIDER_SIZE = 40, WIDER_FRAMES = 10, NARROWER_FRAMES = 10;
    int widerframe, narrowerframe, sizechange;
    int x, xprev, y, speed, effectdelay;
   
    Image[] wider = new Image[WIDER_FRAMES];
    Image[] narrower = new Image[NARROWER_FRAMES];
   
    public Paddle () {
        x = STARTX;
        y = STARTY;
        speed = 0;
        w = W;
       
        paddle = iid.getImage().getScaledInstance(W, H, 0);

    }
   
    public void Move (Direction d) {
        direction = d;
        speed = SPEED;
        switch (direction) {
            case LEFT: {
                dm = -1;
                break;
            }
            case RIGHT: {
                dm = 1;
                break;
            }    
        }
    }
    public void Stop () {
        direction = Direction.NONE;
    }
    public void Wider () {
        if (state == State.NORMAL) {
            state = State.GET_WIDER;
            sizechange = WIDER_SIZE / WIDER_FRAMES;
            widerframe = 0;
            xprev = x;
            for (int i = 0; i < WIDER_FRAMES; i++) {
                wider[i] = iid.getImage().getScaledInstance(w + sizechange * (i + 1), H, 0);
            }
            effectdelay = EFFECT_DELAY;
        }
    }
   
    public void Update () {
       
        switch (state) {
            case WIDE:
                if (--effectdelay == 0) {
                    state = State.GET_NARROWER;
                    sizechange = WIDER_SIZE / NARROWER_FRAMES;
                    narrowerframe = 0;
                   
                    for (int i = 0; i < NARROWER_FRAMES; i++) {
                        narrower[i] = iid.getImage().getScaledInstance(w - sizechange * (i + 1), H, 0);
                    }
                }
                break;
            case GET_WIDER:

                    w = W + sizechange * (widerframe + 1);
                    xprev = x;
                    x -= sizechange / 2;
                    widerframe++;
                    if (widerframe == WIDER_FRAMES) {
                        paddle = iid.getImage().getScaledInstance(W + WIDER_SIZE, H, 0);
                        state = State.WIDE;
                    }
                break;
               
            case GET_NARROWER:
                w = W - sizechange * (widerframe + 1);
                x += sizechange / 2;
                narrowerframe++;
                if (narrowerframe == NARROWER_FRAMES) {
                    paddle = iid.getImage().getScaledInstance(W, H, 0);
                    state = State.NORMAL;
                }                
                break;
        }
       
        if (direction == Direction.NONE) {
            speed -= SPEEDD;
            if (speed < 0) {
                speed = 0;
            }            
        }
     
        int dx = x + speed * dm;
        if (dx + w > XRIGHT) {
            x = XRIGHT - w;
        }
        else if (dx < XLEFT) {
            x = XLEFT;
        }
        else {
            x = dx;
        }    
               
    }
   
    public void Draw (Graphics g, JPanel p) {
       
        switch (state) {
            case GET_NARROWER:
                g.drawImage(narrower[narrowerframe], x, y, p);
                break;
            case GET_WIDER:
                g.drawImage(wider[widerframe], x, y, p);
                 break;
            default:
                g.drawImage(paddle, x, y, p);
                break;
        }
    }
}


When you hit Space Wider is called, and Update and Draw according to main game loop are executed.

Waiting for any info Smiley
7  Game Development / Newbie & Debugging Questions / problems with animation on: 2012-01-24 20:20:29
Hello,

Probably this question is too easy to most of you, but I feel like stuck.

I've got everything ok with moving the image, but when I draw different images (from array), I see some flashing.

You can try the applet here:
http://asphaltgalaxy.com/test2/animtest.html

Press space to see that unwanted effect or press left or right to move.

Shortly about my animation loop:

I've got JPanel:
1  
public class Board extends JPanel implements ActionListener, Runnable {


and there is I think pretty standard run method in it:
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 void run () {

        long beforeTime, timeDiff, sleep;

        beforeTime = System.currentTimeMillis();

        while (true) {

            UpdateGame();
            repaint();

            timeDiff = System.currentTimeMillis() - beforeTime;
            sleep = DELAY - timeDiff;

            if (sleep < 0) sleep = 2;
            try {
                Thread.sleep(sleep);
            }
            catch (InterruptedException e) {
                System.out.println("interrupted");
            }

            beforeTime = System.currentTimeMillis();
        }
    }


My paint method is like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
    public void paint(Graphics g) {
        super.paint(g);
        switch (gamestate) {
            case RUNNING: {
                DrawRunning (g);
             }
        }
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }


And finally DrawRunning runs this method of Paddle class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
    public void Draw (Graphics g, JPanel p) {
       
        switch (state) {
            case GET_NARROWER:
                g.drawImage(narrower[narrowerframe], x, y, p);
                break;
            case GET_WIDER:
                g.drawImage(wider[widerframe], x, y, p);
                 break;
            default:
                g.drawImage(paddle, x, y, p);
                break;
        }
    }


where wider and narrower arrays of images:
1  
2  
    Image[] wider = new Image[WIDER_FRAMES];
    Image[] narrower = new Image[NARROWER_FRAMES];


And arrays are filled in Paddle class when you press space (I've got one image which I resize frame by frame):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
    public void Wider () {
        if (state == State.NORMAL) {
            state = State.GET_WIDER;
            sizechange = WIDER_SIZE / WIDER_FRAMES;
            widerframe = 0;
             for (int i = 0; i < WIDER_FRAMES; i++) {
                wider[i] = iid.getImage().getScaledInstance(w + sizechange * (i + 1), H, 0);
            }
            effectdelay = EFFECT_DELAY;
        }
    }


Any help needed, what and where I am doing wrong?

If I didnt provided some important code, please, let me know... Just didnt want to paste a lot of it to make main logic as clear as possible.
8  Games Center / WIP games, tools & toy projects / Re: Java tower defense game on: 2012-01-18 17:47:08
Nice artwork as I can see. Waitin for any version to try it Smiley
9  Games Center / WIP games, tools & toy projects / Re: Warcraft Remake on: 2012-01-18 17:42:54
What a great job! I liked it very much!

Tried applet, everything wen ok. But after I just closed browser (Mozilla 8, Win XP) with applet, game is still running in background. I still hear music and sounds, java.exe process is consuming cpu...

But anyway, keep working! Looking forward Smiley
10  Games Center / Featured Games / Re: ApoSimple on: 2012-01-13 07:47:33
Is there this game on GameJolt? Because I found very similar game few months ago there and liked it. Very interesting idea and style. Although, a little bit confusing at the beginning.
11  Games Center / Showcase / Re: Fruity Corners on: 2012-01-12 20:38:52
555?!? It's just impossible for me (used mouse and monitor, tapping on monitor not working! ) Smiley

I like quality and graphics. Well done!
12  Games Center / Featured Games / Re: Age of Conquest III on: 2012-01-10 20:05:14
Very cool and addicting game! Spent few hours on sunday playing demo! Love it!
13  Games Center / Archived Projects / Re: Fall And Blocks on: 2012-01-07 09:12:00
That's cool! Now, waiting for results Smiley
14  Games Center / 4K Game Competition - 2012 / Re: Galactic Conquest 4K on: 2012-01-06 12:21:34
Wow, what a fun game! Really addicting! Like it and wish it took part in at least 8k games Smiley
15  Games Center / Archived Projects / Re: Fall And Blocks on: 2012-01-04 16:54:46
Since I used Inkscape for game board background, so sharing here links to some Inkscape tutorials:

http://inkscapetutorials.wordpress.com/suggest-a-tutorial/tutorial-list/
http://2dgameartforprogrammers.blogspot.com/

And exactly that one I used when was creating background for Fall And Blocks: Smiley
http://2dgameartforprogrammers.blogspot.com/2011/10/more-fun-with-gradients.html

Hope it helps!
16  Games Center / Archived Projects / Re: Fall And Blocks on: 2012-01-03 16:27:55
Thanks all of you! Really appreciate every response! It's so motivating. Smiley

@Mads
Quote
I beat the highscore by one point, by the way.  persecutioncomplex

Hmm... I also noticed hi score with max integer value and your name by side. Smiley How did you do that, what were your steps? I mean is it so easy and natural to insert fake score? Sure, I did nothing to prevent that, but there wasn't form like 'input your name and desired high score', anyway someone should at least know, what page to call. I read some threads here about this topic and all I understood, it is close to impossible to make 100% secure functionality. I really need your opinion.

@Grunnt
Quote
However, it stuttered a bit on my (admittedly not so recent) laptop. Perhaps it's generating a bit of "garbage"?

Tested on Celeron 1.4 single core old notebook with Win XP and there was less than 25% cpu usage and memory usage was like constant. So, how could I check whats wrong?
17  Games Center / Featured Games / Re: Square II on: 2012-01-02 20:08:10
Good one. Played on virtual machine full screen and everything went smooth. Liked your fonts. And think it is good to have executables for different platforms, probably you got some headache with that...

And gameplay was like bit too slow on normal board at the beginning... and too fast at the end Smiley

Happy 2012 too!
18  Games Center / Featured Games / Re: Revenge of the Titans on: 2012-01-02 19:21:30
Upgrading drivers didnt help (although I more than sure that there is no normal driver updates for my soundcard, rather 'cosmetic', it was like 2011 July drivers on website, and during installation I saw actually 2008 year version).

But anyway I tried this game on virtual machine and yes, it rocks! Liked it! Smooth graphics and very special atmosphere. Smiley
19  Games Center / Archived Projects / Re: Fall And Blocks on: 2012-01-02 17:43:41
And what about other applets? Is it ok with them on your machine?
20  Games Center / Archived Projects / Re: Fall And Blocks on: 2011-12-31 07:22:32
The applet has earphones on it so it doesn't listen to my keyevent.

hint: I clicked the applet.

Hmmm. What OS r u using? I noticed some problems on some (tested on 2 actually Smiley ) Linux distros. On one of them I just refreshed webpage with applet and everything went ok (without additional click on applet).

So, where to start?

Class where listener is looks like:

1  
public class Board extends JPanel implements ActionListener, Runnable {


And the listener itself in this class is:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
        private class TAdapter extends KeyAdapter {
           
        public void keyPressed(KeyEvent e) {

            int key = e.getKeyCode();

            switch (gamestate) {
                case RUNNING: {
                    switch (key) {
                        case KeyEvent.VK_LEFT: {
                            shape.MoveDirection(blockboard, BlockShape.Direction.LEFT);
                            break;
                        }
                        ...


Where could be a problem?
21  Games Center / Archived Projects / Re: Fall And Blocks on: 2011-12-31 07:14:57
Nice! I loved the effects and the smooth transitions, makes for an overall polished feel. Actually quite amazing for a graphics beginner! Keep up the great work Smiley

Thank you! Glad you liked it!
22  Games Center / Featured Games / Re: Revenge of the Titans on: 2011-12-30 10:49:19
Hmm... not sure what else is important in this case, cause I think other system params are nothing special here:

Win XP Pro SP3, 32bit on i5-2400, 3.5GB RAM.
23  Games Center / Archived Projects / Fall And Blocks on: 2011-12-30 09:51:03
Hello!

Just created my second game, it's a 3billionth Tetris clone: 'Fall And Blocks'. Smiley



Applet is here:
http://asphaltgalaxy.com/test2/fallandblocks.html

Features:
  • Global score
  • 4 sizes of board
  • 3 next shape view modes


Few words about me:

I am new to Java, but not so new to programming (working mostly with Oracle databases/forms/reports). I am reading this forum for several months, and found it very useful. Just do little more searching and your problem is solved Smiley

I got problems with graphics (mean artwork), since I cannot draw. Thanks to modern drawing programs and their tutorials, I can do some very basic art. Smiley

24  Games Center / Showcase / Re: Sokoban Clone on: 2011-12-30 09:24:12
Ubuntu sucks.

You can find a lot of people who will tell you're wrong Smiley But personally for me Ubuntu is better than any other distro. Tried several distros on virtual/old hardware.

And when it comes to Java... It seems that only on Win platforms there are less problems with Java. I'm not so experienced, but reading JGO makes me feel like that.
25  Games Center / Featured Games / Re: Revenge of the Titans on: 2011-12-30 08:39:18
Got strange issue with sound. Samples are repeating very fast many times instead of one time as it obviously should be. I've got not very 'standard' soundcard onboard - EMU1212, but can't remember I experienced any problems with other Win games/apps (but, probably, I didn't run Java games before).

I think it is problem with library you're using. Exactly same issue with 'Square II' featured here, but 'Age of Conquest III' plays sounds and music without any problems.
26  Games Center / Showcase / Re: Sokoban Clone on: 2011-12-30 08:27:57
Still no sound on Ubuntu, got this:

1  
2  
3  
4  
java.lang.IllegalArgumentException: Master Gain not supported
   at org.classpath.icedtea.pulseaudio.PulseAudioLine.getControl(PulseAudioLine.java:89)
   at info.armado.sukoban.Sound.run(Sound.java:51)
   at java.lang.Thread.run(Thread.java:679)
27  Games Center / Showcase / Re: Sokoban Clone on: 2011-12-29 14:35:12
Nice game, well done. Although not really my favorite genre.

On Ubuntu 11.10 with Java 6 under VirtualBox got this one:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
ub_test@ubtest:~/Downloads$ java -jar Sokoban.jar 
00a.lvl
00b.lvl
01.lvl
02.lvl
03.lvl
04.lvl
05.lvl
06.lvl
07.lvl
08.lvl
09.lvl
10.lvl
java.io.IOException: mark/reset not supported
   at java.util.zip.InflaterInputStream.reset(InflaterInputStream.java:286)
   at java.io.FilterInputStream.reset(FilterInputStream.java:217)
   at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(SoftMidiAudioFileReader.java:135)
   at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1111)
   at info.armado.sukoban.Sound.run(Sound.java:42)
   at java.lang.Thread.run(Thread.java:679)

UPD: So I managed to run the game under Ubuntu, although without sound, but graphics and movement were OK. Closed the game and noticed error posted above.

On virtual WinXP everything went smooth.
28  Games Center / WIP games, tools & toy projects / Re: Ant Colony Simulator (not really a game) on: 2011-12-29 14:14:39
One of the ultimate games I want to create is an MMORPG game where all content is generated and controlled by an AI similar to this. Think about it; a game where towns and cities are naturally formed around places with lots of people and travelers; a game where towns need resources to survive and can actually disappear if they are destroyed or they become too unpopular, e.t.c.

This is probably where Dwarf Fortress's Adventure Mode is heading in, oh, another 20 years.  I only ever play Fortress Mode myself, and it also has some pretty interesting emergent behaviors, though not a lot of direct interaction between dwarfs except when they're killing each other...


And it's little bit like Majesty (at least older one). You can stimulate heroes by money (not always), and you never know, will reach your mage level 7 or not Smiley
29  Games Center / WIP games, tools & toy projects / Re: Ant Colony Simulator (not really a game) on: 2011-12-29 14:09:46
Nice simulator, great job! Tried several maze construction strategies... Smiley And yes, they're still searching for food Smiley
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (22 views)
2014-12-14 19:50:38

BurntPizza (43 views)
2014-12-09 22:41:13

BurntPizza (77 views)
2014-12-08 04:46:31

JscottyBieshaar (38 views)
2014-12-05 12:39:02

SHC (52 views)
2014-12-03 16:27:13

CopyableCougar4 (50 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!