Cycle random images in Android

stradf

New Member
I'm beginner to Android / Java development. I just started learning programming and the easiest way for me is to modify open source projects to understand the principles involved.Anyways, I want to do a very simple modification to Bubble Shoot game, 5-10 different background images will be cycled randomly:
  • when every new level is started (but remain the same when the level is just restarted)
  • or much easier: background is changing every single time when the level is restarting or starting
I defined a string array of background drawables:\[code\]<?xml version="1.0" encoding="utf-8"?><resources> <string-array name="random_background"></string-array> <item name="background_01">@drawable/background01</item> <item name="background_02">@drawable/background02</item> <item name="background_03">@drawable/background03</item> <item name="background_04">@drawable/background04</item> <item name="background_05">@drawable/background05</item> <item name="background_06">@drawable/background06</item> <item name="background_07">@drawable/background07</item> <item name="background_08">@drawable/background08</item> <item name="background_09">@drawable/background09</item> <item name="background_10">@drawable/background10</item></resources>\[/code\]The original code define the background on GameView.java in SRC folder:\[code\] mBackgroundOrig = BitmapFactory.decodeResource(res, R.drawable.background, options);\[/code\]Please help me to create an easy way for this idea.Also I have few questions:
  • The xml file must be in res/values correct ? Can I use any file name for it ? For example: random.xml
  • I got this error with the xml file: error: A 'type' attribute is required for item Do I need to setup the type and format for each item ? If yes, what type and which format please ?
  • Can we avoid exceeding the video memory limit ? I mean to load only the current background, and after each use to be flush out before a new random image will be displayed.
Notes: Bubble Shoot source code: https://code.google.com/p/bubble-shoot/Background pictures file names: background01.jpg, background02.jpg, etc.Thank you very much,Paul
 
Back
Top