Natural approach to create a dynamic game engine for Android

175 views Asked by At

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 game engine is an application that runs a game that comes as a bundle of media files (images, audio) + one "description" file (e.g. xml or yaml format) that describes and links different "scenes".
  • A "scene" is just a background image + a background music + different actions that can be triggered with buttons.
  • Typically, clicking a button moves the game to a different "scene".

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:

  • Background image: A bedroom image
  • Background music: bedroom_music.mp3
  • Actions:
    • Leave the room => Go to Living room scene
    • Leave the room through the window => Go to Garden scene
    • Pick up alarm clock => Add clock to inventory
1

There are 1 answers

0
Gino Biervliet On BEST ANSWER

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.