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.
About the author
Programmer.
#22
Now I can't get it to respond to touches ...
I have one object on the scene and I want it to move when I touch it, for some reason the device is not responding to my touches
10/30/2013 (9:08 am)
Thanks Tim, it works now.Now I can't get it to respond to touches ...
I have one object on the scene and I want it to move when I touch it, for some reason the device is not responding to my touches
function Game::create( %this )
{
hideSplashScreen();
// Load scripts.
exec("^game/scripts/guiProfiles.cs");
exec("^game/scripts/scenewindow.cs");
exec("^game/scripts/scene.cs");
// create scene window
createSceneWindow();
// create scene
createScene();
mySceneWindow.setScene(myScene);
setRandomSeed(getRealTime());
myScene.clear();
// enable mouse touch and mouse clicks
mySceneWindow.setUseWindowInputEvents(true);
mySceneWindow.setUseObjectInputEvents(true);
%clone = new sprite();
%clone.class="dummyClass";
%clone.setImage("game:arrowBox");
%clone.setSize(15,15);
%clone.setPosition(0,0);
%clone.GravityScale = 0;
%clone.setUseInputEvents(true);
myScene.add(%clone);
}
//-----------------------------------------------------------------------------
function dummyClass::onTouchDown(%this, %touchID, %worldPosition)
{
%this.setLinearVelocityX(5);
}
#23
10/30/2013 (9:24 am)
Does the same code work on iOS? I noticed some of the input examples in the sandbox did not work on iOS or Android which I assumed was due to how they were written and only worked on desktop. Although I would think onTouchDown would work on mobile. Are you getting any errors in logcat?
#24
I have installed :
JDK for windows
then
adt-bundle-windows with eclipse and now ???
What I must do for test torque2D on android ??
Thanks to everyone help me :-)
Bye
10/30/2013 (11:04 am)
Hei ... stupid question but ho w can debug torque2D on android ??I have installed :
JDK for windows
then
adt-bundle-windows with eclipse and now ???
What I must do for test torque2D on android ??
Thanks to everyone help me :-)
Bye
#25
@Amjad, Tim - onTouchDown should always work on both desktop and mobile. All of the sandbox input should work on all platforms as well, I am not aware of anything that is desktop only in the included toys. To help narrow this issue down, could it potentially be related to this? github.com/GarageGames/Torque2D/issues/118
Can you see if by touching below the object (or above, to the left, right), it registers the callback? Try SceneWindow::onTouchDown as well, if that works you could do a work-around by using picking to select the object to make it move.
10/30/2013 (12:13 pm)
@Andrea - there is a link to an android development guide in post #4 of this thread. Did you read that yet?@Amjad, Tim - onTouchDown should always work on both desktop and mobile. All of the sandbox input should work on all platforms as well, I am not aware of anything that is desktop only in the included toys. To help narrow this issue down, could it potentially be related to this? github.com/GarageGames/Torque2D/issues/118
Can you see if by touching below the object (or above, to the left, right), it registers the callback? Try SceneWindow::onTouchDown as well, if that works you could do a work-around by using picking to select the object to make it move.
#26
10/30/2013 (12:56 pm)
Ops is true thanks :-)
#27
ShapeVectorToy doesnt work at all on iOS/Android. All you get is a black screen.
PickingToy input doesn't work on iOS/Android.
I dont know if they work on desktop or not. I wasn't sure if whatever is broken in PickingToy was his same issue or not. I don't know if it uses onTouchDown or not.
10/30/2013 (5:23 pm)
The ones I was referring to are:ShapeVectorToy doesnt work at all on iOS/Android. All you get is a black screen.
PickingToy input doesn't work on iOS/Android.
I dont know if they work on desktop or not. I wasn't sure if whatever is broken in PickingToy was his same issue or not. I don't know if it uses onTouchDown or not.
#28
10/30/2013 (5:47 pm)
I commited the armeabi version of libopenal.so and I commited the source code for freetype2 that the static library was built with. the freetype lib should be fine but if anyone has any problems with it on an armeabi device let me know.
#29
10/30/2013 (7:33 pm)
Wow, this is really cool! I won't be trying this out for a while, but massive kudos to Tim and anyone else who was involved in making this happen. Thanks for the hard work!
#30
the LogCat keeps giving me this error whenever I touch the screen:
@Tim - are you saying I should download the changes you made to make the problem of touching go away?
10/31/2013 (3:40 am)
@Mike - the issue is not related to %worldPosition, I tried touching all over the screen but with no luck what so ever, SceneWindow::onTouchDown did not work either.the LogCat keeps giving me this error whenever I touch the screen:
10-31 12:05:29.898: E/NativeActivity(3202): channel '40536f50 com.garagegames.torque2d/com.garagegames.torque2d.MyNativeActivity (client)' ~ Failed to receive dispatch signal. status=-11
@Tim - are you saying I should download the changes you made to make the problem of touching go away?
#31
10/31/2013 (4:51 am)
No my changes are to fix audio on your device. Have you tried the stock sandbox on your device? Does it work with input?
#32
I'm not using the sandbox to test my example above, I wonder why the touches do not work with it.
10/31/2013 (6:15 am)
I've just tried the PointForceControllerToy, and for some reason the touches work fine with this toy!! I'm not using the sandbox to test my example above, I wonder why the touches do not work with it.
#33
10/31/2013 (6:21 am)
Have you read the input events documentation? There have been changes to Torque 2D MIT event handling, which leads me to believe you've missed something. The likely culprit is that you forgot to use addInputListener
#34
10/31/2013 (7:54 am)
@Michael - I've used addInputListener() and that did not do the trick, but you did inspired the solution though, using appCore folder that comes with the engine as is works fine when using the sandBox, but for a standalone version of T2D (which I'm using now) one must do some minor changes to the appCore folder as explained in the getting started tutorial. Now onTouchDown() works fine.
#35
The C++ code will also automatically hide the keyboard if the user presses the back button.
Note: There is a bug in the NDK that google has not fixed yet with pressing the back button to hide the keyboard. As far as I can tell it affects android 4.2.2 and up (possible 4.2). I commited a fix for it but you have to manually copy it into your NDK. If you are using NDK r9, you can simply overwrite your NDK file with the one I uploaded. IF you are using a different version you will have to manually merge it if the files are different.
It is located in the torque repo at: torque2d/engine/compilers/android/NDKKeyboardBugFix/android_native_app_glue.c
The file is located in the NDK at: android-ndk-r9/sources/android/native_app_glue/android_native_app_glue.c
You will need to do a clean and build after fixing the NDK file.
If anyone uses the keyboard and has issues let me know.
10/31/2013 (9:28 am)
I have updated the repo with some virtual keyboard code. you can call toggleAndroidKeyboard(true) to show the keyboard and toggleAndroidKeyboard(false) to hide it. There is also a isAndroidKeyboardShowing() script function that returns a boolean if you need it. The C++ code will also automatically hide the keyboard if the user presses the back button.
Note: There is a bug in the NDK that google has not fixed yet with pressing the back button to hide the keyboard. As far as I can tell it affects android 4.2.2 and up (possible 4.2). I commited a fix for it but you have to manually copy it into your NDK. If you are using NDK r9, you can simply overwrite your NDK file with the one I uploaded. IF you are using a different version you will have to manually merge it if the files are different.
It is located in the torque repo at: torque2d/engine/compilers/android/NDKKeyboardBugFix/android_native_app_glue.c
The file is located in the NDK at: android-ndk-r9/sources/android/native_app_glue/android_native_app_glue.c
You will need to do a clean and build after fixing the NDK file.
If anyone uses the keyboard and has issues let me know.
#36
I will test it as soon as I download the repo, meanwhile, a big question pops to my mind: where does the keyboard input gets stored? In another words: how can we get the user's input?
I must say that Android support is really a big PLUS for T2D 2.0, now the community can develop games and apps for a large number of mobile devices since Android's market share is about 81% according to this article. Good job.
10/31/2013 (10:06 am)
Tim, you are awesome.I will test it as soon as I download the repo, meanwhile, a big question pops to my mind: where does the keyboard input gets stored? In another words: how can we get the user's input?
I must say that Android support is really a big PLUS for T2D 2.0, now the community can develop games and apps for a large number of mobile devices since Android's market share is about 81% according to this article. Good job.
#37
keyboard events work just like windows so they will be dispatched to torque the same way. I now have in my local build the torque Textfield open the keyboard when you click on it and if you type on keyboard it gets added in textfield just like desktop. I did notice the keyboard virtual map doesnt work 100% so I have to work on fixing that still before I upload.
The other thing I want to look into if I have time is to modify the opengl code so that the screen can slide up so if you click on a textfield that is under the keyboard, the screen will slide up so the user can see the textfield as they type.
10/31/2013 (6:06 pm)
Thanks :)keyboard events work just like windows so they will be dispatched to torque the same way. I now have in my local build the torque Textfield open the keyboard when you click on it and if you type on keyboard it gets added in textfield just like desktop. I did notice the keyboard virtual map doesnt work 100% so I have to work on fixing that still before I upload.
The other thing I want to look into if I have time is to modify the opengl code so that the screen can slide up so if you click on a textfield that is under the keyboard, the screen will slide up so the user can see the textfield as they type.
#38
11/01/2013 (12:55 am)
Just popped-in to give you a big thumbs-up Tim. Great job.
#39
Another question: how to change the orientation from landscape to portrait? Also how to get the current orientation?
11/01/2013 (4:36 am)
@Tim - great. Will be waiting for the 100% working version to test.Another question: how to change the orientation from landscape to portrait? Also how to get the current orientation?
#40
@Amjad Orientation is handled through the AndroidManifest.xml on Android so there are no complicated changes for orientation. If you open it in eclipse and view the xml code you will see android:screenOrientation="sensorLandscape" just change that to sensorPortrait and it will be portrait instead of landscape and still allow the user to rotate the device upside down. There are a lot of options you can use in that field. Like if you want to lock to portrait but not allow them to turn the device upside down you can just use portrait instead of sensorPortrait I believe. I think you can use | to specify more than one like if you wanted your app to support landscape and portrait. I havent tested all of those so if something does not work let me know. You can see all of the options here:
developer.android.com/guide/topics/manifest/activity-element.html
As for getting the current orientation, there is a C++ function called _AndroidGameGetOrientation() but I am guessing you want a script call so I can add that to the repo. Ill try and do that today.
11/01/2013 (5:30 am)
@Melv Thanks!@Amjad Orientation is handled through the AndroidManifest.xml on Android so there are no complicated changes for orientation. If you open it in eclipse and view the xml code you will see android:screenOrientation="sensorLandscape" just change that to sensorPortrait and it will be portrait instead of landscape and still allow the user to rotate the device upside down. There are a lot of options you can use in that field. Like if you want to lock to portrait but not allow them to turn the device upside down you can just use portrait instead of sensorPortrait I believe. I think you can use | to specify more than one like if you wanted your app to support landscape and portrait. I havent tested all of those so if something does not work let me know. You can see all of the options here:
developer.android.com/guide/topics/manifest/activity-element.html
As for getting the current orientation, there is a C++ function called _AndroidGameGetOrientation() but I am guessing you want a script call so I can add that to the repo. Ill try and do that today.
Associate Tim Newell
Max Gaming Technologies
If you look at the bottom of the documentation:
The splash screen is a Java dialog that has to be hidden from TorqueScript when the game loads. It is currently in the toys code but if you start with a new script setup you will need to add hideSplashScreen() into your scripts when you want to hide it.
Make sure you read that entire section titled "Notes on Project Setup for Deploying to a Device"