So now every thing is ready now you can start developing game
ok before creating app you need to know something important k kon sy folder main kya kaam hota hai yahan main aapko kuch example dunga
src: yeh source folder sab sy main hota hai. Sari app ka source code yahan likha hota hai
res: yeh resources folder hota hai is main aap saray resources daltay hain jaisa k
anim: Compiled animation files
drawable: Bitmaps
layout: UI and view definitions
values: Arrays,colors, dimensions, strings, and styles
xml: Compiled arbitrary XML files
raw: Noncompiled raw files
Iska structure kuch yun hota hai
gen: yeh auto generated folder hota hai jab aap dubug krtay hain koi b application to yeh auto generate krta hai filesCode:/res/values/strings.xml /res/values/colors.xml /res/values/dimens.xml /res/values/attrs.xml /res/values/styles.xml /res/drawable/*.png *.jpg *.gif *.9.png /res/anim/*.xml /res/layout/*.xml /res/raw/*.* /res/xml/*.xml /assets/*.*/*.*
Ab aap start krain
1.Click file--> new --> android application project
2. Just write the details as written in picture
3. Then uncheck create custom launcher icon and create activity
Aap ka project kuch yun ban kar aega aur important chez iski xml file hain Android Manifest.xml
(Jaisa k mainay aap ko pehly btaya k main is main aapko java nai btaonga is k baad java k b tutorials dunga par abhe sirf code dunga)
Ab sab sy pehly hum java ka aik package bnaegy java ka package bananay k lye src-->right click-->package uska naam rkhain com.example.hang
Ab pehlay hum java ki aik class bnaegay main class
Right click on your package-->new-->class
class name MainActivity
Ab yahan sab sy important cheez hai aik baat samajhna k android ki aap chalti kaisay hai,
Kisi b app main aap aik ya bht sari activities banatay hain kam sy kam aik to hoti hi hai.
Yeh activities btati hain k aap ki aap kya karay ge jaisa k aik activity app open karnay ki phr agr usay pause karain to kya aur phr usay resume karain to kya hoga yeh sab activities hoti hain, in activities ko aap xml file jo k Androidmanifest.xml hai us main define krtay hain.
Ab aap ko yeh baat clear hojani chahyeh
source code /srcfolder main jata hai jo k hum java main bana rahay hain
uski activities hum androidmanifest.xml main likhaingy
aur is puri aap k lye jo strings ya bitmaps yani drawables chahyeh hongay woh hum resources /res folder main dalaingay
Yeh samajh agaya to ab agay chaltay hain
Code:package com.example.hang; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { public final static String EXTRA_MESSAGE = "com.example.hang.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void startGame(View view) { Intent intent = new Intent(this, LevelSelectActivity.class); // EditText editText = (EditText) findViewById(R.id.edit_message); //String message = editText.getText().toString(); //intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); } @Override public void onBackPressed() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }
aap is java code ko apni MainClass main copy kr lijye or phr ctrl S press krain jo errors hon unhain chor dain kyun k yeh error baki classes k na honay ki wjah sy hain jo hum abhe bnaegay
ab aap apni androidmanifest.xml kholain aur us main yeh type krain
Yeh code aap ny android:theme="@style/AppTheme" > k nichay aur </application> k oper yani in dono k beech main paste krna haiCode:<activity android:name="com.example.hang.MainActivity" android:launchMode="singleTop" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
yeh code kya keh raha hai aik nazar samajhtay hain
android:name="com.example.hang.MainActivity" = yeh is main activity ko pehlay run krnay ka keh raha hai
android:launchMode="singleTop" = single top aur standard main jo fark hai woh technical hai aap ko baad ki classes main smjhaonga
android:label="@string/app_name" > = hum strings ki aik xml file bnaengay jahan sy yeh code app_name uthaya jaega
ab aap dobara apnay package com.example.hang par ajaye aur right click kar k aik aur class banaye
LevelSelectActivity
java code of class:
Yeh code aap paste kar dijye.Code:package com.example.hang; import android.os.Bundle; import android.app.Activity; import android.view.MenuItem; import android.view.View; import android.support.v4.app.NavUtils; import android.annotation.SuppressLint; import android.content.Intent; public class LevelSelectActivity extends Activity { @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the text view as the activity layout setContentView(R.layout.activity_level_select); } /** * Set up the {@link android.app.ActionBar}, if the API is available. */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } public void easyStart(View view) { Intent intent = new Intent(this, PlayActivity.class); intent.putExtra("level", 0); startActivity(intent); } public void hardStart(View view) { Intent intent = new Intent(this, PlayActivity.class); intent.putExtra("level", 1); startActivity(intent); } public void expertStart(View view) { Intent intent = new Intent(this, PlayActivity.class); intent.putExtra("level", 2); startActivity(intent); } @Override public void onBackPressed() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }
Ab dobara apni androidmanifest.xml ko kholain aur yeh code </activity> aur </application> k beech main paste kar dain
Code:<activity android:name="com.example.hang.LevelSelectActivity" android:launchMode="singleTop" android:label="@string/title_activity_level_select" android:parentActivityName="com.example.hang.MainActivity" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.hang.MainActivity" /> </activity>
Bookmarks