Show Posts
|
|
Pages: [1]
|
|
1
|
Game Development / Newbie & Debugging Questions / Re: problems with animation
|
on: 2012-01-27 16: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
|
|
|
|
|
2
|
Game Development / Newbie & Debugging Questions / Re: problems with animation
|
on: 2012-01-26 16: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  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  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? 
|
|
|
|
|
4
|
Game Development / Newbie & Debugging Questions / Re: problems with animation
|
on: 2012-01-25 18:10:22
|
To add more knowthebetter suggestions  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  You think this will help me to solve paddle flashing on resize problem? 
|
|
|
|
|
5
|
Game Development / Newbie & Debugging Questions / Re: problems with animation
|
on: 2012-01-25 17: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  ). 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  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. 
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / Re: problems with animation
|
on: 2012-01-25 17: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?  For me it almost always flashes (those few times I think I saw that it didn't flash I can address to my imagination  ) 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 
|
|
|
|
|
7
|
Game Development / Newbie & Debugging Questions / problems with animation
|
on: 2012-01-24 21: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.htmlPress 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.
|
|
|
|
|
9
|
Games Center / WIP games, tools & toy projects / Re: Warcraft Remake
|
on: 2012-01-18 18: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 
|
|
|
|
|
10
|
Games Center / Featured Games / Re: ApoSimple
|
on: 2012-01-13 08: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 21:38:52
|
555?!? It's just impossible for me (used mouse and monitor, tapping on monitor not working! )  I like quality and graphics. Well done!
|
|
|
|
|
16
|
Games Center / Showcase / Re: Fall And Blocks
|
on: 2012-01-03 17:27:55
|
Thanks all of you! Really appreciate every response! It's so motivating.  @Mads 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.  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 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 21: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  Happy 2012 too!
|
|
|
|
|
18
|
Games Center / Featured Games / Re: Revenge of the Titans
|
on: 2012-01-02 20: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. 
|
|
|
|
|
20
|
Games Center / Showcase / Re: Fall And Blocks
|
on: 2011-12-31 08: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  ) 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 / Showcase / Re: Fall And Blocks
|
on: 2011-12-31 08: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  Thank you! Glad you liked it!
|
|
|
|
|
23
|
Games Center / Showcase / Fall And Blocks
|
on: 2011-12-30 10:51:03
|
Hello! Just created my second game, it's a 3billionth Tetris clone: 'Fall And Blocks'.   Applet is here: http://asphaltgalaxy.com/test2/fallandblocks.htmlFeatures: - 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  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. 
|
|
|
|
|
24
|
Games Center / Showcase / Re: Sokoban Clone
|
on: 2011-12-30 10:24:12
|
Ubuntu sucks.
You can find a lot of people who will tell you're wrong  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 09: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 09: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 15: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 15: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 
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|