I am making a simple rpg game that uses animation to move characters around. In one scene I am working on there is 4 things that happen:
1)The character walks on screen 2)A gun shot is heard when the user clicks on screen the first time and a bullet hole appears in a window. 3) The user is given two options, shoot back or get in car. The shoot back button does what you think it does and the character pulls out a gun and another gunshot is heard. 4) If get in car is pressed the character walks to the car, gets in and drives away. The problem is the program force closes if you click the shoot back button and then click get in car. The problem that I see from debugging is "OutOfMemory" error. The game runs perfectly on the Nexus One but any other phone with an inferior processor force closes. Could anyone point out a way to save memory on this? Do I have to purposely finish() the previous activities or is there a problem with the code below (note that the threads it calls just are for timing the gunshot sounds to line up with the animation). public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.scene1); mSoundManager = new SoundManager(); mSoundManager.initSounds(getBaseContext()); mSoundManager.addSound(3, R.raw.gun_silencer); mSoundManager.addSound(5, R.raw.glass_break); character_img = (ImageView) findViewById(R.id.character_img); character_img.setBackgroundResource(R.anim.scene1_anim); scene1_anim = (AnimationDrawable) character_img.getBackground (); scene1_anim.setOneShot(true); Scene1Thread = new Scene1Thread(); Scene1Thread2 = new Scene1Thread2(); scene1_bg_img = (RelativeLayout) findViewById (R.id.scene1_bg_img); btn_shoot_back = (Button) findViewById(R.id.btn_shoot_back); btn_getin_car = (Button) findViewById(R.id.btn_getin_car); btn_shoot_back.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { btn_shoot_back.setVisibility(Button.INVISIBLE); btn_shoot_back.setClickable(false); character_img.setBackgroundResource (R.anim.scene1_shoot_back); scene1_shoot_back = (AnimationDrawable) character_img.getBackground(); scene1_shoot_back.setOneShot(true); scene1_shoot_back.start(); Scene1Thread2.start(); } }); btn_getin_car.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { btn_getin_car.setVisibility(Button.INVISIBLE); btn_getin_car.setClickable(false); if (btn_shoot_back.getVisibility() == Button.VISIBLE) { btn_shoot_back.setVisibility(Button.INVISIBLE); btn_shoot_back.setClickable(false); } character_img.setBackgroundResource (R.anim.scene1_getin_car); scene1_getin_car = (AnimationDrawable) character_img.getBackground(); scene1_getin_car.setOneShot(true); scene1_getin_car.start(); } }); shot_vibrate = (Vibrator) getSystemService (Context.VIBRATOR_SERVICE); character_img.post(new Starter()); btn_gun_shot = (ImageButton) findViewById(R.id.btn_gun_shot); btn_gun_shot.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { scene1_bg_img.setBackgroundResource (R.drawable.scene1_bg_shot); Scene1Thread.start(); shot_vibrate.vibrate(250); btn_gun_shot.setClickable(false); btn_shoot_back.setVisibility(Button.VISIBLE); btn_getin_car.setVisibility(Button.VISIBLE); } }); } class Starter implements Runnable { public void run() { scene1_anim.start(); } } Please and Thank you.
-- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en