Level selection screen, such as Farm Tower, Angry Birds, Cut the Rope, etc.?

I want to create a level screen for my game, similar to those in Angry Birds, Farm Tower and Cut the Rope (the part where you select worlds or the part that looks like a gallery widget). I wanted to know that this is the easiest way to attack this.

How do I change the Gallery view to work?

+7
source share
2 answers

Views form a hierarchy . Make Gallery GridView .

If you want to adapt the code from the Gallery tutorial, change the ImageView to a LevelSetView and create a LevelSetAdapter that extends the BaseAdapter and overrides its getView method. Here is the beginning.

 public class HelloLevelsGalleryActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Gallery g = (Gallery) findViewById(R.id.gallery); g.setAdapter(new LevelSetAdapter(this)); } 

To understand the best adapters: reference or this video in 2 minutes.

In addition, a question has been asked here .

+4
source

Here is the idea of ​​creating a level selector using the Gallery view.

Let's look at this example so that you have a code base: http://developer.android.com/resources/tutorials/views/hello-gallery.html

So, at the top you will have your level screens. When the user clicks on it, this method starts (taken directly from the example).

 gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { startLevel(position); } }); 

Perhaps your startLevel will look something like this:

 public void startLevel(int position){ Resources res = getResources(); String[] levels = res.getStringArray(R.array.level_classes); try{ Intent i = new Intent(this, Class.forName(levels[position])); startActivity(i); } catch (ClassNotFoundException e) { e.printStackTrace(); } } 

Again, a very simple example, since I have no idea how you store your levels if you use a database or not, etc. In addition, your classes for each level are likely to be in different packages (e.g. com.game.levelone, com.game.leveltwo), and you will need to import class packages so as not to get a ClassNotFoundException But this should get you started in the right direction.

+2
source

All Articles