[HELP] Looking for the best solution for putting game controls over my game

  • Replies:3
Stephen Kong
  • Forum posts: 17

Mar 23, 2012, 7:36:38 PM via Website



I am trying to add several game controls and stats display (i.e. score..etc) over my game similar as the sample above. What would be the best solution? I am thinking of overlay. If overlay is the best solution, would anyone able to offer some code sample of building a overlay control+display on top of a game? Any information would be greatly appreciated. Thanks.

Reply
Jeremiah
  • Forum posts: 775

Mar 26, 2012, 8:14:29 AM via Website

If you looking for some example code, there is a free open source game engine called AndEngine. It has abilities for an onscreen controller. You may be too far in your game to use AndEngine, but might get some help looking at the source: http://code.google.com/p/andengine/source/browse/#hg%2Fsrc%2Forg%2Fanddev%2Fandengine%2Finput%2Ftouch%2Fcontroller

Reply
Stephen Kong
  • Forum posts: 17

May 6, 2012, 2:10:21 AM via Website

This is my main.xml layout file

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<home.net.RedAlertView android:id="@+id/RedAlertView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fire!"/>

</FrameLayout>

I have two questions.
1. According to the document, FrameLayout stacks views one on top of other, How do I ensure the Button view is always stacked on top of my custom game view?
2. The custom game view constantly refreshes itself, how could I be certain it does not overwrite the button view (even if the button view is stack on top of it)?

Reply
Jeremiah
  • Forum posts: 775

May 8, 2012, 7:40:12 AM via Website

Use View.bringToFront() on your button view, each time you refresh your game view. You shouldn't have to do this for each frame though, only if you make layout changes and such. You don't want to call View.bringToFront every frame you draw.

— modified on May 8, 2012, 7:42:57 AM

Reply