Eric Leibenguth
Eric Leibenguth

Reputation: 4277

Natural approach to create a dynamic game engine for Android

I want to create a simple game engine for Android. I am fairly new to the OS, and I want to be sure that I do not start off in the wrong direction.

My requirements are fairly simple:

The first question I have is: Should I have one or multiple Activity objects to create the scenes? That is: Is it better to have one single activity which content is dynamically updated when clicking the buttons; or to have one activity per scene.

Note that the difficulty is that the game engine has to generate the activities dynamically. So the list of buttons cannot be hard-coded inside a layout file, as they come from the description file. I have found this example that shows how to create a layout dynamically. Would you recommend using the same approach?

Assuming I use a single activity for all scenes, it means that when I switch scene (by clicking a button), I need to fully update the view (background and buttons). To do that, should I rather remove each element one by one with removeView(), or rather create a new blank layout with setContentView(), and then populate it with the new background and buttons?

Any advice is welcome.

Example of scene:

Upvotes: 2

Views: 174

Answers (1)

Gino Biervliet
Gino Biervliet

Reputation: 194

Activities are usually used for different "views". For example: A chat app will have a lobby activity and starts a new activity when opening a chat screen.

Following the analogy above I would say you should use only one activity and load the correct scene in that activity. There could be an activity controlling these changes? Or an activity that shows a layout while loading.

Having said that. I think you have to design custom objects that can be converted to buttons/walls/monsters or such. This will make the dynamically loading of buttons/objects easier. In Android you must define buttons/visual objects in a layout xml file. This file will be loaded by an activity. I don't think these xml files can be modified on the fly.

Upvotes: 1

Related Questions