as soon as I'll publish my java 3d game
and some discussion about games and developing
send your comment about that what you want from mobile game
and which games you like and are you played games in mobile or no.
wait for your comments
works about 3d animation and game
Hosted by eSnips |
Advanced programming II: images and text
Now we want focusing on making better game. For better game we need some text for showing score and some images for maps and other thing and at last a better graphics for getting your game more reality .
In design of 3d models you need getting texture from building and objects that you want to use in game. Some texture maybe force to distortion your model and even maybe you can’t see anything. And of course more high graphics texture and models may not be seen well in some old phone. For example when you download this game for p990 sonny erricson you see a picture like it
But when you want to download it for k750 from same company (sonny ericsson) you will see some graphics problem and maybe even you can’t see some models in older phones.
Add text and images and some functions
You can add text and images to your games with Graphics class and bind Graphics3D to it .You should add text and images to graphics after bind it to Graphics3D . it is an example code
g3d.bindTarget(graphics,true,Graphics3D.ANTIALIAS|
Graphics3D.TRUE_COLOR);
g3d.render(_world);
g3d.releaseTarget();
graphics.setColor(0x990000);
graphics.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
graphics.drawString("corner", 90, 150,
Graphics.TOP | Graphics.RIGHT);
In first code we bind target graphics(from Graphics class) to g3d(from Graphics3D) and in second line we render my world class . After release your g3d object you can change your graphics object and add image or add text .For add text I use three line for set color and font and text.
Add images is like that and only you need add function drawimage and image object to your code.This image can be maps or character picture or other thing.You can add some function also to your program for controlling move of cameras or objects in your game.I add a sample code for this porpose.
if(y>-20)
Y=-20;
With this code camera will be stopped if it reached to left wall.In 3ds max wall y position was 20 and
Camera will be moved to Y with this code
camera.setTranslation(X, Y, Z);
You can see more in this project
I add a sample project for more discuss in light and cameras. it is only a camera moving in between walls(textures are from internet).I'll add gun and other effects to it in next time.You can also edit 3d model in way you want. This is my model in 3 direction:top,camera,left and perspective
This model have a camera and 3 light and you should draw your model on base of your camera(upper right picture) and if you want use another cameras also you should configure your model on base of them. In this model camera id is 14 and for loading camera in program this code is enough
Camera camera;
Camera=(Camera)(Myworld.find(14));
Camera position in this model is your person eye.You can move camera in every place with this code
m.setTranslation(x,y,z);
For example you can move it with pointer with this code
protected void pointerPressed(int x, int y) {
m.setTranslation(x,y,z);
}
Pointerpress is a function that invoked when a pointer pressed and x,y is pointer location in screen .You can say that when pointer pressed (x,y) location in screen camera can move.you can add image and text to game for this purpose also. In next post i add text and image to this project for getting better result from this project.
In every game you should select your lights and cameras carefully and move them on base of your objects moves specially in 3d games.
In this 3d model you see three light( free spot) and one camera and panel and ball(sphere).this is a sample game for moving a ball in panel.For using it you should export in m3g After do that maybe you see a view such this in a m3g player
As you see you may lost some graphics on base of your m3g exporter and your 3d software now you are ready for moving your lights and cameras.
2.moving your lights and cameras
Java have two class for moving light and cameras in m3g files with name Light and Camera.
For moving light and cameras you can use this codes
Light l=(Light)(Myworld.find(lighted);//getting your desired light
l. setTranslation(x,yz);//move it to x,y,z location
Camera m;m=(Camera)(Myworld.find(cameraid);//get your desired camera from your world
m.setTranslation(x,y,z);// move it to x,y ,z location
now you can run your game in netbeans emulator (see picture)but you should now that your game maybe presented in mobiles differently on base of their graphics.
You can send your comments about this post .I'll be glad for them.
For starting in programming with netbeans first I upload a sample java mobile game project that you can download it and run it or change it and even make a new game.
3d model making
1-for starting programming first you should have 3d model maker .this software should can export models to m3g.I using 3ds max 2008 but you can also use any 3d software like blender and a m3g exporter with it.Blender and m3g exporter are free.Maya is another good software for it but is not free.Every box and sphere you create in this software ,have an id in m3g that give you access to them and You can rotate and move this object .Graphics of this model maybe have some problem in
Some phones on base of their graphics.
Netbeans project information
2. After make your 3d model and export it now you are ready for programming .you should export your 3d model to subfolder "src\res" from your project folder .
My game engine is panel1 class and game canvas is "Canvas" and middle is hellomiddlet. 3ds model is in res folder (game1.max)with m3g file and you can change this model in way you want.your project name in netbeans is your project folder(unzip file after download) and you jar file is in dist folder.You can run it from mobile .In next post I'll explain my project functions and cods and models.
About functions and code
Panel1 class have two functions setmeshpositions and movemesh.setmeshpositions (15,35,35,35) means that your object with id 15 is positioned in 3 dimension space in xyz coordinate(x=35,y=35,z=35) and movemesh(15,"up",5) moving your object with id 15 to up direction in 5 unit.For example in this code
int state = getKeyStates();
if( ( state & DOWN_PRESSED ) != 0 ){
panel.movemesh(15, "up", 5);
state value is 1 when your using a key(in otherwise is 0) or no and DOWN_PRESS value say that you pressed down or
no and if two of them are true mesh move up 5 unit in up direction.you can change this code with replace up with down or like that.in next post I'll write some more about this codes and functions.
Midlet
When you start to programming with java for mobile ,first class you build is midlet .Midlet is an interface between you and mobile. In netbeans you can easily add midlet automatically or with right click in project and in new menu click in visual midlet. In visual midlet you have a form by default and actions belong to it and in graphical interface you can easily add text or other thing to form but if you dont wnat to have form in your program you need only midlet.This class have functions like startApp,destoryApp,startMidlet and like .This function say's what you want to do when midlet started or your program started and etc.In middle you can also switch display of your program between graphics and forms that you make or add your command to your program. It is better that you have this class and game canvas and game engine in different file. It give your program better readability and of course better performance.You can use your game engine in other programs and your game canvas in other midlet and many other features.
Your game engine can also contains more class in base you programs.
__________________________________________________________________________________
Gamecanvas
In mobile programs you have also a gamecanvas (midpcanvas) class.This class contain function for pressing or dragging or clicking keys or pointers and you can add your functions to them.it is an example
protected void keyPressed(int keyCode) {
int action = getGameAction( key );
switch(action)
{
Case DOWN:
MOVEDOWN();
.
.
.
}
}
DOWN,UP,RIGHT,LEFT are predefined value's in gamecanvas class and their value is same with returning value from getGameAction(key) when you click down ,up,right and left key in mobile.
A game canvas also has paint function .With paint and repaint function you can draw your graphic world(you'll learn about it in following posts) .You can change your graphics world everywhere and repaint it everywhere also.But you should know more repaint in bad place in class forced to some problem in your game graphics .
With this primary information you are almost ready for start programming .