Pages

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

No comments:

Post a Comment

linkwithin

Related Posts Plugin for WordPress, Blogger...