Game Development Community

Torque 2D for Android Ready

by Michael Perry · in Torque 2D Beginner · 10/28/2013 (11:47 am) · 122 replies

Android port is ready for testing. If you pull latest from the development branch, you can start using it. I don't have the time to write a formal blog yet, so spread the word. Feel free to start posting bug reports based on your own Android testing.
#81
11/09/2013 (6:29 am)
and could you debug on windows now?
#82
11/11/2013 (3:36 am)
I've been really busy so I have not had a chance to debug it yet. I do not have a windows machine setup for android development as I mostly use Mac OSX.
#83
11/11/2013 (5:26 am)
thanks for the reply.
#84
11/14/2013 (2:06 am)
How can I access a remote file, modify and then save the changes? Is it doable for Android?
#85
11/14/2013 (7:17 am)
@tim,
for debugging which debugger u were using?
eclipse's default one
or
arm's DS-5 Debugger ?
#86
11/14/2013 (7:42 am)
ahh,
finally debugging is working.
dont know what i did.but it is now working.

i have skipped step 4,6,7(c).

most probably,as i have skipped step 6 so there is no gdb.setup file in my project folder now.

it seems step 6 is not required for everyone.

i will do a postmortem later and post the result here.

still biggest problem is that my eclipse takes 1.3 hour to rebuild.
#87
11/17/2013 (12:20 am)
hi ashan, how could you make the debug works? could you write the windows debug document?
#88
11/17/2013 (12:21 am)
if there is a new version, let me know, thx.
#89
11/17/2013 (2:57 am)
"hi ashan, how could you make the debug works? "
yes it is working now.

" could you write the windows debug document?"
still i am not sure what changes i did in my eclipse.
but the biggest culprit was my workplace name.
make sure that none of your folder name contains space.
and skip step 4,6,7(c).

i will try to manage some time to sit down with t2d again.
#90
11/18/2013 (5:25 am)
@Amjad: What do you mean by remote file? Like on a server? Or do you mean on device outside the apk?

@ahsan: I use the default ADT one, which if you are using the ADT bundle that would be the default eclipse one for android projects.

Sorry everyone I havent been able to address the issues yet, I have been in crunch mode working on a deadline for another project.

#91
11/18/2013 (5:39 am)
@Tim: I meant on a server, but I also would like to know where can I store game files (players' profiles and game attributes) on android system?
#92
11/18/2013 (6:14 am)
They both work the same was as the other platforms in T2D. You need to preface your path with Platform::getUserDataDirectory() to get the cache dir on android just like iOS. If you look back at comment 61, there is a bug with reading and writing to cache right now that I still need to look into. As far as server goes take a look at TCPObject or HTTPObject in t2d.
#93
12/01/2013 (9:50 pm)
My OS is Windows 7. I am trying the android setup following the guide

github.com/GarageGames/Torque2D/wiki/Android-Development-Guide

I did all the steps until step #7, it build the project.

I copied my game main.cs and assets to the place mentioned.

Then I defined a emulator, and did run... the emulator shows up, but nothing happens. Here's the log

[2013-12-01 21:33:54 - Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath": CreateProcess error=2, The system cannot find the file specified
[2013-12-01 21:34:08 - Torque2D] ------------------------------
[2013-12-01 21:34:08 - Torque2D] Android Launch!
[2013-12-01 21:34:08 - Torque2D] adb is running normally.
[2013-12-01 21:34:08 - Torque2D] Performing com.garagegames.torque2d.MyNativeActivity activity launch
[2013-12-01 21:34:08 - Torque2D] Automatic Target Mode: Preferred AVD 'nexus_one' is not available. Launching new emulator.
[2013-12-01 21:34:08 - Torque2D] Launching a new emulator with Virtual Device 'nexus_one'
[2013-12-01 21:34:22 - Torque2D] New emulator found: emulator-5554
[2013-12-01 21:34:22 - Torque2D] Waiting for HOME ('android.process.acore') to be launched...
[2013-12-01 21:39:56 - Torque2D] emulator-5554 disconnected! Cancelling 'com.garagegames.torque2d.MyNativeActivity activity launch'!


Also this warning

Invalid project path: Include path not found (Torque2Djniincludelibjpeg).

#94
12/02/2013 (1:11 am)
". the emulator shows up, but nothing happens. Here's the log"

present t2d android port most probably does not work with emulator.no one have luck with emulator.

u need an android device to test the game.

that means if u do not have any android device then present t2d android port is not for u.
+your device have to meet minimum api requirement.
otheriwse u will have to do some extra work.

******************************
"Invalid project path: Include path not found (Torque2Djniincludelibjpeg). "

"engine\compilers\android\jni\Android.mk" contains this reference

"$(LOCAL_PATH)/../../../lib/ljpeg \"

so make sure that u have ljpeg library under
"engine\lib\"
#95
12/02/2013 (2:16 am)
I defined an Intel X86 AVD, as explained here

stackoverflow.com/questions/1554099/slow-android-emulator

and that allows the emulator to start much faster, but with an error message for the Torque 2D project as

[2013-12-02 01:57:55 - Torque2D] Android Launch!
[2013-12-02 01:57:55 - Torque2D] adb is running normally.
[2013-12-02 01:57:55 - Torque2D] Performing com.garagegames.torque2d.MyNativeActivity activity launch
[2013-12-02 01:57:55 - Torque2D] Automatic Target Mode: Preferred AVD 'x86_WVGA' is not available. Launching new emulator.
[2013-12-02 01:57:55 - Torque2D] Launching a new emulator with Virtual Device 'x86_WVGA'
[2013-12-02 01:58:03 - Emulator] emulator: device fd:656
[2013-12-02 01:58:03 - Emulator] 
[2013-12-02 01:58:03 - Emulator] HAX is working and emulator runs in fast virt mode
[2013-12-02 01:58:05 - Torque2D] New emulator found: emulator-5554
[2013-12-02 01:58:05 - Torque2D] Waiting for HOME ('android.process.acore') to be launched...
[2013-12-02 01:58:42 - Torque2D] HOME is up on device 'emulator-5554'
[2013-12-02 01:58:42 - Torque2D] Uploading Torque2D.apk onto device 'emulator-5554'
[2013-12-02 01:59:15 - Torque2D] Installing Torque2D.apk...
[2013-12-02 01:59:18 - Torque2D] Success!
[2013-12-02 01:59:18 - Torque2D] Starting activity com.garagegames.torque2d.MyNativeActivity on device emulator-5554
[2013-12-02 01:59:18 - Torque2D] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.garagegames.torque2d/.MyNativeActivity }

I am new to Android development, running on the emulator was just a first test, next I'll try to connect to a device
#96
12/02/2013 (6:22 pm)
I switched to a Mac. After step 6 of

github.com/GarageGames/Torque2D/wiki/Android-Development-Guide

the clean step on ADT, I get these errors

**** Build of configuration Default for project Torque2D ****

/Volumes/Home/android/android-ndk-r9b/ndk-build all 
Android NDK: ERROR:jni/Android.mk:openal-prebuilt: LOCAL_SRC_FILES points to a missing file    
/Volumes/Home/android/android-ndk-r9b/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting    .  Stop.
Android NDK: Check that jni/../../../lib/openal/Android/armeabi-v7a/libopenal.so exists  or that its path is correct   

**** Build Finished ****

[edit] this seems to be my mistake, the .so library file is not existent on my local repo copy, ignore
#97
12/02/2013 (9:36 pm)
And.. success!

I was able to get the toys up and running on my Android device... looks great!

Thanks, Torque team, for adding this feature.

Note: For some reason my game does not start, I only get the Torque logo. I just copied my main.cs and my modules folder into

engine/compilers/android/assets

My game was done using the master branch, replicating the script code from the master. I am guessing here that the development branch adds a couple of Android specific variables to the scripts.

Is this the case?

As a bonus, I was able to resuscitate the old Torque t2dTextObject (the one that generates a font from a UTF file) into the current Torque 2D engine. I will post a resource on that soon.

#98
12/03/2013 (10:28 am)
Make sure you look at the bottom of the documentation under "Notes on Project Setup for Deploying to a Device"

Specifically step 3 tells you how to add code to your game to hide the splash screen after your game is loaded. There are also some $platform checks again Android in the default scripts you might want to look at. Setting up the screen correctly, hiding the splash screen, setting up device fonts I think are the 3 big things that the $platform check is for.
#99
12/04/2013 (1:28 am)
Thanks, Tim.

Yes, I found this code buried deep inside the Toys framework.

if ($platform $= "Android")
    	hideSplashScreen();

Could this call be done instead in the engine android code? Since it only happens for Android and it has to be called anyway :-)
Or does it depend on some sequence that has to be called from script?

The other call that is needed is

%resolution = GetAndroidResolution();

in the script canvas creation.

There are a couple of font names specific to Android in the Toys GUI.

The only GUI I have is this, and Arial Bold looks sharp clean on my Android, as it did on iOS.

if ( !isObject( GuiMLTextProfile )) new GuiControlProfile( "GuiMLTextProfile" )
{
  fontType       = "Arial Bold";
  fontSize       = $ML_font_size;
  fontColor      = "0 0 0";
  autoSizeWidth  = true;
  autoSizeHeight = true;  
  border         = false;
  justify        = "center";
  modal          = false;
};

This is used in a GuiMLTextCtrl class, a class that allows text to be rendered with HTML like tags, really handy.

%this.GuiTextCredits = new GuiMLTextCtrl()
  {
    canSaveDynamicFields  = "0";
    Profile               = "GuiMLTextProfile";
    HorizSizing           = "width";
    VertSizing            = "height";
    Position              = "0 0";
    Extent                = %extent;
    MinExtent             = "8 2";
    canSave               = "1";
    Visible               = "1";
    hovertime             = "1000";
    lineSpacing           = "2";
    allowColorChars       = "0";
    maxChars              = "-1";
  };

  %this.GuiTextCredits.SetText( %text );  
  %this.guiOverlay.addGuiControl( %this.GuiTextCredits );
  canvas.pushDialog( %this.guiOverlay );

Thanks again for doing this Android port, I am super excited about releasing our games for Android.

So far everything looks good, I just have to rewrite some logic code size for Android sizes.




#100
12/04/2013 (7:24 am)
The reason I did the splash screen hiding in script is so the developer can control when the splash goes away. If I do it in engine, depending on the game, it may take longer to load assets, etc and have a black screen between the splash hiding and the game starting.

The font changes are if you want to generate fonts on device. You can generate font cache on desktop and use that just fine. Android devices have custom fonts (most with the name droid in them). I made the device font loading code allow partial matches since not all android devices have the same fonts. So specifying droid just grabs the first font on the device with droid in the name. My nexus 7 when i upgraded from 4.2.2 to 4.3 a lot of the fonts changed. You also have a third option which is to put a font folder in assets folder and put ttf fonts in it. I personally would use font cache, but the other two options were a requirement from GG.

I am working on freeing up some time to address some bugs etc in this thread. If you notice anything not working right just post in here and I will get around to it.