Loading Resources in Game
Hi,
I want to ask about loading resource(s)in game.
As per now I have two ideas of loading resource(s)
1. To load all the resources(sound & images) before the game starts.
2. Or to load and unload images depending upon state of game . For example main menu background should be unloaded while entering to game and game background should be unloaded while entering main menu.
Which of the above two ways can optimize the game play more. And are there another ways to do resource loading ?
My another question is that I am testing a game developed by me on phones like MOTO V3i, but the game hangs and after compressing the images, I can run the game but game play is very slow, compared with other phones like K810, N70.
but when I install other online available games on V3i, whose game play is similar to my game, these games run faster than my game.
what might be the problem which makes my game slow?
Thank you for you time to read my post and looking forward for replies.
Kai
Re: Loading Resources in Game
here,this are the way to make a game loading screen:
Usually we do it in 2 different ways for showing a realistic progress bar.
1) If we have 50 images to be loaded for every level, we increase the progress by 2 after loading every image successfully. This is the simplest way you can do it and its the most efficient way doing it though not exactly a realistic one.
2) You can create a separate thread for showing the progress bar and use different thread for loading the resources. After every resource is loaded you have to increase the progress according to the size of resources loaded. This is not recommended as threading is always an issue in many devices. And knowing the percentage of a single resource loaded cannot be determined using J2ME.
___________
[url=http://www.smartkids.dk/]Børnetøj[/url]
[url=http://www.lingeriebrasandthongs.com]sexy lingerie[/url]
Re: Loading Resources in Game
[QUOTE=kai_buki;596955]I want to ask about loading resource(s)in game.
As per now I have two ideas of loading resource(s)
1. To load all the resources(sound & images) before the game starts.
2. Or to load and unload images depending upon state of game . For example main menu background should be unloaded while entering to game and game background should be unloaded while entering main menu.
Which of the above two ways can optimize the game play more. And are there another ways to do resource loading ?[/QUOTE]
This is not just a matter of "optimization". Many phones will not have enough memory to load all the images at the same time. Yes, you should load the images you need for the given state. States would include "splash screen", "menu", "game level 1", "game level 2" (for games that use different images in different levels).
[QUOTE=kai_buki;596955]My another question is that I am testing a game developed by me on phones like MOTO V3i, but the game hangs and after compressing the images, I can run the game but game play is very slow, compared with other phones like K810, N70.
but when I install other online available games on V3i, whose game play is similar to my game, these games run faster than my game.
what might be the problem which makes my game slow?[/QUOTE]
The V3i has much less memory and much less cpu performance than the K810 or N70.
Nokia Series 60s make a very bad choice for game development, if you hope to run your game on a wide range of devices. They are fast, and they have much more memory than other devices. The V3i is actually quite a good choice, because it has limited performance and memory. If your game runs OK on a V3i, it will run well almost anywhere! :)
Without knowing much about your game, or the games you're comparing it with, it's hard to say why yours is slower. A game on a V3i should be able to run at around 10 to 15 frames per second. Possibly, you are making too many calls to drawImage(). It is usually faster to draw a small number of large images, than a large number of small images.
Graham.
Re: Loading Resources in Game
Hi,
And Grahm,He must check that images are creating in the loop.If you will create the images in a loop then I am more then sure that it will hang the game.Please check that you are not loading the any resource in loop.
AFA then drawing is concern,you must not call the repaint() in a infinite loop,if not required,then call the repaint() on the keypressed().This is also a critical factor for the frame rate of the game.
Please check that whether you are not doing this.
Re: Loading Resources in Game
Hmmm... not sure what you mean by not doing work in loops... if he's using the "two thread" model, then I'd [i]everything[/i] I possibly can inside a loop.
[code]
public void run() {
while (state != STATE_EXIT) {
long startTime = System.currentTimeMillis();
// game logic
int nextState;
switch (state) {
case STATE_LOADING_PLAYER_IMAGE:
playerImage = loadImage("/player.png");
nextState = STATE_LOADING_ENEMY_IMAGES;
break;
}
// allow screen to update
repaint();
serviceRepaints();
state = nextState;
// regulate frame rate
long endTime = System.currentTimeMillis();
long elapsed = endTime - startTime;
long sleepTime = FRAME_DURATION - elapsedTime;
if (sleepTime < MIN_SLEEP) {
sleepTime = MIN_SLEEP;
}
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
// ignore: doesn't happen on CLDC-1.0 anyway
}
}
}
[/code]
In this model, putting repaint(), or any game logic, inside the keyPressed() method means you will have two threads updating the game state in parallel, and screen updates occuring while the game state is only half updated. I have seen many games with game logic in the keyPressed() method, and they always prove problematic in porting, even though they may behave fine on the original device (usually a Nokia) they were written for.
Re: Loading Resources in Game
Hi,
By the loop I mean to say that images are not created in the method gets infinite calls.