A few moderately basic graphics questions...

I’m using very basic paint, drawImage type commands in my games and I have some (probably) simple graphics questions.

Resizing: at the moment my games play at 800x600 resolutions (I like the photo realism!) and I use display mode to alter the users screen to this resolution so they can play full screen. This works OK’ish on most folks screens but on others it doesn’t work at all or just shows a black screen. I know images can be resized so is it possible to resize the whole screen to fit the users current resolution? can it be done easily? and is it moderately efficient?

Darken: Is it possible to darken a whole screen and then slowly un-darken it? I tried painting a black rect over the whole image and slowly making the image transparent but this wasn’t very pretty or gradual.

Mist: I’m after a similar effect to the above in a different game but this game is set on an ice planet with falling snow and I wanted the “mist” to clear to show the game. Any ideas?

Image: I was quite happy with the look of the game above with the snow but a few people pointed out that the images I’m using are at odds with the game. I have bubbles floating around in the mist and snow above ice caps etc and some bubbles contain bombs that, when you shoot the bubble, the bomb will drop down onto the surface and restrict your movement. These bombs look like the round cartoon bombs with a lit fuse that sparkles away. They said that the old fashioned image of the bomb looked at odds with the space game - I think they’re right but I’m at a loss as what to use instead. Any thoughts?

Sorry, Im sure someone else will come up with better answers, in the mean time…

Resizing : There are a variety of strategies that people have implemented. I new with libgdx, its just a matter of creating the viewscreen and using a camera to use your desired resolution (still tricky to get right, but on this one I would advise finding tutorials that are relevant for your setup)

Darken: Something like that could be accomplished with a black background and just adjusting the alpha from the foreground, however, there are multiple strategies that work.

Mist: I’ve not done this myself, but I think one plan is to make a white particle overlayed on the map at like 50% alpha, then it’s just playing with the particles to get it to look right.

Images: Ultimately, your choices are to find free resources, buy some, or take the time to draw stuff out… I’m sorry, but there’s not much point in sugar coating this one, either you need to LEGALLY obtain resources or create them yourself.

For darkening:


for (int i = 0; i < size; i++) {
	int c = video[i] & 0xffffff;
	video[i] = (c >>> 1 & 0x7f7f7f) + (c >>> 2 & 0x3f3f3f) + (c >>> 3 & 0x1f1f1f) + (c >>> 4 & 0xf0f0f);
}

@bmanmcfly - I suspect it’s a little late to rewrite the games using a games library, I’m not sure I’d enjoy writing the games that way either though that’s a personal preference. Is there no way of transferring the Graphic thing into an image and then resizing that. I’ll admit it doesn’t sound to performant but as long as I can get ~30 FPS I’d be happy. Regards darkening the screen, would you know how to grab the graphics object into an image that I can then play with? Regards images, I’m quite happy drawing but my problem is I can’t work out what to draw that might fit into the game - it’s set on a frozen world with cartoon style graphics, ice mountains in the background, snow falling and bubbles to shoot that float through the mist. The bombs I have currently look good and tell you that it’s not a good thing running into them. The problem is that spherical bombs with fuses are unlikely to be found in space games.

@darkening - thanks for the example code but can I ask what video is?

video is the pixel array that you want to draw to.

I wish I could offer better knowledge on this…

1 - I understand that feeling, especially when it comes to the realization that you’d have to rewrite a significant amount of code, etc… There was a point when I felt the same way (I was writing c++ for directX, and realized that android / ios games was more realistic and achievable for me), I just went for the engine because then I wouldn’t be starting over from scratch… that said, I do understand your desire to make a system for yourself, where you know how everything works with everything else.

2 - I wouldn’t know a good way how to accomplish that, a strategy I might try might be something to the effect of, when the program starts, do a detection of the screen size and resolution, and then have a variety of the sprite sheets to handle some of the more common resolutions and then use that data to determine which assets to load… others probably will have better suggestions.

3- I’m not sure myself, I do know with the “sprite” class that libgdx offers, you can get the image and directly manipulate the alpha and other aspects of the image… might be useful to check out the source they use to accomplish that. Otherwise, I’m afraid I’m little help here too.

4- Just throwing this out there, have you considered changing from the old school cartoon bomb to something like the ww2 era sea mines (they look like a sphere with a bunch of needles sticking out)??
I mean, that might still be unlikely in a space game, but it might be a bit less of an inconsistency…

alternatively, if you change it to something that looks more like a missile, or bomb dropped from a plane, maybe with a blinking light to signify ‘danger’?

There’s no real right or wrong here.

I have implemented a strategy in my games where the game screen cannot be resized (however my games are only for desktop so I’m sure it wouldn’t work on mobile). I run the game with a border layout in the center panel, which is always the same, 900 x 700. But I also have a left, right, bottom, and top panels. When the game starts, I grab the screen size and adjust the panels accordingly so the game screen is always in the center of the screen.


public static Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();
public static JFrame f = new JFrame("My Game");

/*
 * ENSURE GAME IS ALWAYS CENTERED
*/
public static double screenWidth = SCREEN_SIZE.getWidth();
public static double hcenterPlacement = screenWidth / 2 - 450;
public static double screenHeight = SCREEN_SIZE.getHeight();
public static double vcenterPlacement = screenHeight / 2 - 350;

leftPanel lp = new leftPanel(0, 0, (int) hcenterPlacement, (int) screenHeight);
rightPanel rp = new rightPanel(0, 0, (int) hcenterPlacement, (int) screenHeight);
topPanel tp = new topPanel(0, 0, (int) screenWidth, (int) vcenterPlacement);
bottomPanel bp = new bottomPanel(0, 0, (int) screenWidth, (int) vcenterPlacement);

f.setLayout(new BorderLayout());
f.setResizable(false);

f.add(lp, BorderLayout.LINE_START);
f.add(tp, BorderLayout.PAGE_START);
f.add(rp, BorderLayout.LINE_END);
f.add(bp, BorderLayout.PAGE_END);
f.add(myGame, BorderLayout.CENTER);

I’ve approached the problem from a few angles already and pretty much dislike the approaches I’ve tried. My current method where it changes the resolution of the users screen for the duration of the game is my favourite so far but it doesn’t work consistently on all users screens. I shy away from using libraries because it takes me longer to work out how to use them than it does writing the games! (sad but true). Using multiple sets of graphics and code to handle the movement is ok but it leads to quite complex code and there’s no real guarantee that the users screen matches the resolutions you’ve coded for. Keeping the game in a fixed window in the centre of the screen certainly works but you just end up with a small game in the middle of a big black screen which would bug me. It’s a shame you can’t just assign the graphics to an image variable and then resize the image on the fly. Better still if you could just tell java to use an 800x600 screen and make it full screen.

I like the idea of the sea mine and will try that out.

I’ve played games that have done just that… so, it is doable to just “stretch” graphics to fit the screen, just the result isn’t always as hoped… but it is POSSIBLE, even if I’m not sure how.