Pages

Thursday, October 28, 2010

about canvas class and using it in mobile game

If you want using keys or touch or graphics in your game you should use canvas class.Canvas class have predefined function for detect key press or drag or screen  touch and also important paint function .First you should add new canvas class with right click on your project and go new and select MIDP canvas…..

In this class you’ll see some function like this

protected  void keyPressed(int keyCode) {
   }
  
   /**
    * Called when a key is released.
    */
   protected  void keyReleased(int keyCode) {
   }

   /**
    * Called when a key is repeated (held down).
    */
   protected  void keyRepeated(int keyCode) {
   }

……………..

……………

…………….

……………

they are contains code that running when key pressed or released or repeated or…you can add code like draw string in keypress and create text when key pressed .Now you should running canvas in your game .For this purpose you should add code like this in startApp function in your middlet.

 Display.getDisplay(this).setCurrent(new MIDPCanvas());

jus thisWinking smile

in next post I’ll describe how you can detect fire,back,numbers,..keys and pointer into your software 

Friday, October 22, 2010

First view of java mobile app code and change it

When you build a java mobile game in software(like netbeans IDE or eclipse..)

first thing you‘ll see is  a middlet class .Middlet class used for handling start and

initialize and interface of java mobile applications. In netbeans you have sample

screen that can add button or text or image or like that .just you should drag your desired items from right side to screen and then go to source

 

netbeansscreen

screen is interface of your project in netbeans

For example you  have pre defined string seeing in screen and want changed it when middlet started. Code is like this

public void startMIDlet() {
       // write pre-action user code here
       switchDisplayable(null, getForm());
             stringItem.setText("my name is dawood");
       // write post-action user code here
   }

startMIDlet is function that using in every middlet .In netbeans for adding interface to screen using a form , should calling when middlet started.For this purpose have this code switchDisplayable(null, getForm());

and then add this for changing text stringItem.setText("my name is dawood");

and run it in emulator

emulator1

in start for do more thing in java games you should add canvas class that i’ll describe later

Saturday, October 16, 2010

about objects in your game(in Android)

  Game contains objects and environment and you should now how coding them.They are defined by class keyword .see this code for example

package com.example.helloandroid;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class HelloAndroid extends Activity

{

/** Called when the activity is first created.

*/ @Override

  public void onCreate(Bundle savedInstanceState)

  {

  super.onCreate(savedInstanceState);

TextView tv =  new TextView (this)tv.setText("Hello, Android"); setContentView (tv);

}

}

this is sample code for showing hello word in android( get from here)

Package contains you project content.For running your project in ide you should add required codes.Import keyword using for add this code.Public means that your object is visible to project or package.helloAndroid is your main project(environment) and onCreate is function of objects that used to create a text in device(i’ll describe code later,see source for some help for now).Your code can be changed on base of your algorithm. Your algorithm can be like this :

1.add codes for running games

2.create  HelloAndroid environment(project)

3.set text “hello, Android”

4.show them

Now you can add a line to algorithm “set text when you clicked on 5” and change code also.For now is sufficient ,I’ll describe more in following posts.For coding using eclipse and adt plugin and android sdk  and run your project and see result like this

hello_world_5

Thursday, October 7, 2010

start coding for your game

now we can start to coding for game.you can modeling your world

when coding your game  but it confuse you. It is better  that first

modeling and then coding and if it isn’t satisfying restart your process.It

is called new version!can be called 0.0.1 or things like that .In version

number commonly  first digit describe mane change in your game and

second describe partial change and third contains number of build(run)

of your game(on base of company strategy) .Now you should design

algorithm of your game before start to  any codes.Algorithm is your

game or software description in sample language(not in codes).For

example for add two digits algorithm is

1.get first number and save it

2.get second number and save it too

3.add two number

4.save result and print

see Algorithm definition and everything here

in next  posts i will  describe a sample algorithm and codes of

games .For now is sufficient …one minute somebody miss algorithm  and

going to coding without   it,It is true just about too sample game ,In

other games You spend many time and maybe see a failed project!

Friday, October 1, 2010

load 3d models in your java games(part 2)

        Now you should design your models .Main format using for java games is m3g file.Software that you using for design should be export your models to m3g .When you using even good software like 3ds max 2010 it is possible that lose some  graphics in  your models because m3g formats reduce 3d models size and graphics for better working in mobile device.

Blender

Blender is free 3d design tools for making animation and your models.For start you can use this tools for export your models into m3g

and see result in m3g viewer  if you don’t want pay more for software like that.Blender need python  installed in your computer 

blender

for seeing your result in  viewer  you can use tools like this from MascotCapsule .This tools also  have exporter  for h3t and convertor for change  h3t to m3g formats. and have better result from normal m3g exporter but h3t exporter plugins used only in 3ds max and maya. 3ds max and maya  have better result than blender but aren’t free .With 3ds max and maya you can design high graphics models and then reduce polygons and export it to m3g.

 

3dsmax2010

linkwithin

Related Posts Plugin for WordPress, Blogger...