Mich Robinson

Ranch Hand
+ Follow
since Jun 28, 2009
Merit badge: grant badges
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
8
Received in last 30 days
0
Total given
16
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mich Robinson

Excellent, thank you.

Am I right to worry about the amount of space being used or do modern PC's and laptops have so much space now that it's not worth caring. I don't notice any slow down in my game from doubling the size but I just worry that someone with an even older PC than mine might start having issues.
1 year ago
I'm just curious but can you get the space used by an array of BufferedImage? I'm currently using:
Everything works fine but I was thinking of doubling the size of the array to provide more granularity of the sky images but then started wondering how much space (KB) this might take up. Is there a simple way of finding out?
1 year ago

Carey Brown wrote:

This worked great when using a single buffered image and fixed the performance issue. I then figured why not create an array of 25 bufferedImages and initialise them all before play and that would fix things completely. I couldn't work out how to change the declaration of the buffered image into an array. I tried various ways but couldn't work out the syntax. I tried the following plus variations and also trying things in a loop but no luck. Any suggestions for the correct syntax?
1 year ago
Thanks, that's what I needed to know. Thanks for everyone's help.
1 year ago

Piet Souris wrote:Apart from that, it is possible to create several BufferedImages that you can draw to, so that in a repaint you only have to draw the correct BI, and do some custom painting over that. Whether that is suitable, I don't know. Another possibility is that you do the drawing in another thread, so that a repaint only requires drawing that BI. If you repaint every 20 ms, say, than this will give you 20 ms to get that drawing done. Just some thoughts.


That was roughly how I was hoping to do it but I don't know how to set a colour in a BufferedImage and then start filling rectangles. I can easily handle all the timing issues but I just don't know how to draw to the image variable. Was hoping for a really simple code snippet. Is it something like:
1 year ago

Carey Brown wrote:You'd have to explain for us how you determine your starting and finishing colors and the colors in between, and the Y distance between the start and end rows.

Do you compute them or use a look up table?

In the example code I gave there's an array of colours called SkyColours. These are adjusted each time the sky colour changes (if the health is low, if the weather is bad, if a something bad is about to happen). The array goes from 0 to 80 as the rectangles of colour are 5 y pixels wide and the sky is drawn down to about 2/3 of the screen.  
1 year ago

Piet Souris wrote:Indeed, have a look at the Paint-interface and the Gradient- and TexturePaint classes. And there is also the MultipleGradientPaint class, in the forms of a Linear and Radial version.

Thanks but I worry that this seems like a really complex way of doing what I want. I'll freely admit my current solution is too slow on low powered laptops but, if I could build an image using setColor and fillRect, then that wouldn't be an issue - can I not do this in Java?

The sky in question is this one.
1 year ago
I'm nearly finished a game where the sky changes colour dynamically with the users health etc. I draw the sky with lots of fillRect commands and changing the colours gradually as the y position moves down the screen. I like the effect but I'm finding my method of drawing the sky is quite slow.

Is there a way of drawing to some sort of Image variable so that I can just display the image once rather than filling lots of rectangles each time?

Code at the moment is like this:



Thanks for any suggestions. If possible, I'd prefer suggestions that don't use fancy libraries as I simply prefer using the basics. Thanks for your time.
1 year ago
I don't think I have access to a profiler so I spent a bit of time looking for likely suspects in my code and then playing the game for approximately 30 mins each time and manually getting some stats. If calls take less than 1ms then they show as 0ms.

I looked into assigning the offscreen buffer to the onscreen buffer. I'll admit it's not very efficient but it just showed up as running in 0ms each time.

A few things could be moved to a background thread (collisions between bullets and things and things and other things, the movement of explosions and smoke etc) but these again seemed to run fairly quickly. I'm not sure it would be worth the effort to create a separate thread. There'd also be the inevitable issues from having 2 threads playing with the same data. There is a fancy sun animation that could also run independently but, again, it ran fairly quickly.

The major culprit seemed to be a drawExplosions call which mostly ran very quickly (average of 0ms) but there were 5 calls when it took longer than 20ms and one call that took 41ms. It would be totally OK if the paint was happening in the background but, because it's running in the main loop, there's a slight pause in play. The explosions are either flames, solid bits that fly through the air when aliens are shot or particle effects. It's the particle bit which seems to take the time as one explosion might have 20 small rectangles of colour being drawn with the colour slowly fading to transparent. I think I can get round this by seeing what type of explosions affect the draw times and then monitor the time to age out these explosions more quickly when timings are getting affected.

I assume there's no easy way of altering my existing structure so the paint simply happens in the background? (I'm reading through the article that was linked to).

2 years ago
I believe that's what I'm doing. I write to the offscreen framebuffer "og" and, when the work's done, I write it to the main framebuffer "g". That's done in the current paint routine. The game is fairly smooth at 28 FPS (at 800x600) but obviously the paint is being done in the main loop. This means that if there's any delay in the drawing then this delay is reflected in the movement. It doesn't happen often, maybe once every 10 mins on a slowish PC, but it's annoying. This is the main reason for trying to get the paint done outside the loop.

I was hoping for a simple hint/explanation on how I could tweak my code but maybe that's not possible with how it is.
2 years ago
I'm not actually sure what a Swing display is It's in full-screen exclusive mode if that helps and the resolution has been changed to 800 x 600. I will admit that it doesn't work for wide screen laptops as it just creates the game in a window. The display is created just using lots of drawImage calls. Not sure if it helps but the title screen looks a bit like this.

Is there a simple way of getting the paint method to run independently of the main method using the structure I have?
2 years ago
I'm in the middle of writing a game and I'm fairly pleased with it's progress. However, at the moment, I call paint directly from the main game loop. So the FPS is linked directly to the main loop. I'd like to have the paint method running independently so the FPS will be independent of the main loop but I'm not sure how to do this.

I tried to show the bits of code that illustrate my question. Can anyone suggest how to get paint running independently?  Preferably in a way that a fool like me can understand



2 years ago
Thanks for the advice. I'll admit I come from a very procedural background and find OO a little weird. I did wonder why I saw definitions of arrays in the 2 formats ow I know.
Is there any performance cost in using arrays like this? or do I need to be more careful with garbage collection? I know this might not look pretty but it's infinitely better than the other approaches I've tried.

Many thanks for the fast responses!
Much appreciated.
4 years ago
I'm trying to develop a fairly flexible routine to move text  and images around a screen as part of a games library. There's a whole bunch of params that can be used so the position part might have X & Y and optionally a starting X & Y or perhaps no position info in which case it goes in the centre of the screen or perhaps it might reference one of the items on screen in which case the message will get printed near by. I have similar options on movement and timings and colours plus other random stuff. I don't want to have a single method with a 100 params. I tried defining different versions of the method that used different sets of params but I'd end up with 100's of methods instead. Today I started experimenting with passing a number of variable length arrays for the position, movement and timing info. This looked like a viable solution but

Is there a way of writing it like (A) that I'm missing?
Is there a better approach altogether?
The problem with (B) is that it looks messy and I'm not sure whether defining and creating all these arrays is efficient as it's used in various real time games.

Thanks for reading
4 years ago
Thanks for the replies. The manuals are useful when you know what you're looking for but personally I just don't know. I don't use maven etc but one of these days I might work it out. The post about the jars made me wonder what would happen if I just put the jar files in a zip along with the exe. This seemed to work when I created a new directory for the program but unfortunately it didn't work when a friend downloaded the zip, extracted it and tried to run it. It unpacked ok but nothing happened when they clicked the exe. If I did the same on my PC it runs fine. The exe was created by launch4j and is supposed to include its own java run time etc. I have to admit this is a little infuriating.

Any other suggestions for generating an exe program that people can just run? The game plays fine but my goal is to put the program on Steam and have it loaded (and run) from there.
4 years ago