Libgdx detect wrong keycode while using macOS - libgdx

i'm new in libgdx and i'm trying to learn to use this framework. I'm used to code on ubuntu but recently I purchased a macbook in order to dev on it.
While my code is working perfectly on both OS. There is only one bug that remains on my program.
When I try to make my character move "on a top down view rpg style", It seems that Libgdx detect my keyboard as a QWERTY, while I can ensure that there is 0 Keyboard layout/mapping installed as a qwerty. Only a AZERTY one. MacOs is also configured as a French system.
Is there a other special way for "apple" machines so that your sprites moves on a screen in libgdx ? Until now I did like this :
if (Gdx.input.isKeyPressed(Input.Keys.Z))
player.setY(player.getY() + GameSettings.playerSpeed * dt);
if (Gdx.input.isKeyPressed(Input.Keys.S))
player.setY(player.getY() - GameSettings.playerSpeed * dt);
if (Gdx.input.isKeyPressed(Input.Keys.D))
player.setX(player.getX() + GameSettings.playerSpeed * dt);
if (Gdx.input.isKeyPressed(Input.Keys.Q))
player.setX(player.getX() - GameSettings.playerSpeed * dt);
In the end when my "z" key is pressed nothing happen (on macOS only) but if I press "w" it works just fine.
Thanks for the futur explanations !

If you create an InputAdapter/InputProcessor you can detect what keycodes are being called when you press each key.
Here's the link to it on the wiki.
Gdx.input.setInputProcessor(new InputAdapter () {
#Override
public boolean keyDown (int keycode) {
System.out.println("Key Down Event, keycode: "+keycode);
System.out.println("Z keycode: "+Input.Keys.Z);
return true; // return true to indicate the event was handled
}
});

Related

Libgdx Timer pause's on lost focus?

I noticed if I use GDXs Timer class on a default, newly created LibGDX project it will not fire at all while the application is minimized or not in focus.
At least this is true on Desktop deployment Windows 10.
JAVAs own timer class, meanwhile, fires regardless of focus.
A simple example app to demonstrate the difference;
#Override
public void create () {
//gdx timer (does not update when focus lost);
//------------------
com.badlogic.gdx.utils.Timer.schedule(new com.badlogic.gdx.utils.Timer.Task(){
#Override
public void run() {
long currentTime = System.currentTimeMillis();
Log.info("____GDX_____________________:"+currentTime+"_________");
}
}
, 0
, 1.0f );
//java timer (updates when focus lost);
//-----------------
Timer test = new Timer();
test.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
long currentTime = System.currentTimeMillis();
Log.info("___JAVA____________________:"+currentTime+"_________");
}
}, 0, 1000);
}
Running this you can clearly see both logs firing when in focus, and only Javas when not in focus.
My questions are;
a) Is the behavior of LibGDXs timer expected, or have I done something wrong in setup? The description of LibGDXs timer doesn't seem to mention the auto-pause.
b) I wish my application to run in the background unless explicitly paused. Merely,say, alt+tabbing should not be enough.
Should I just switch to using JAVAs timer? Does this have cross-platform implications?
Thanks,
Darkflame
a) Yes, the documentation of TimerThread, which handles Timer, says:
Manages the single timer thread. Stops thread on libgdx application
pause and dispose, starts thread on resume.
b) Since libGDX Timer is nothing special than just a Thread, which listen for application change (pause, resume etc.), with list of tasks, it should be fine to use Java's Timer. Since it is from 1.3 (and the libGDX target is 1.6) it should not have any cross-platform implications.

Handle back key event on Windows Phone 8?

How to handle back key event in Cocos2dx 3.3 Windows Phone 8 C++?
Many thanks
Use the HardwareButtons.BackPressed event to handle the back key press. Set the Handled property on the event args to true if you want to avoid the default behaviour of closing the app.
Check this one -
http://discuss.cocos2d-x.org/t/solved-windows-phone-8-framework-back-button-handling/5732.
I've found the solution with cocos2dx 3.3
In header file .h
virtual void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);
And cpp file
void MrGreen::onKeyReleased(EventKeyboard::KeyCode keyCode, cocos2d::Event *event)
{
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
{
}
}

Windows phone 8.1 BackPressed not working properly

Windows phone 8.1 new to world. Basic function is back button click. Is that function not working properly is this windows phone 8.1. Is that behavior or i'm made mistake.
Below code using in Homepage but this code calling from all other class too while clicking back. I need to access below method only on Home page .
Please check below code and refer me good solution.
Please look my code:
public HomePage()
{
this.InitializeComponent();
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
}
Thanks
It is working properly. The BackPressed event is working app-wide. Two options that come to my mind:
write eventhandler that would recognize the Page in which you currently invoke it - simple example can look like this:
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null) return;
if (frame.Content is HomePage)
{
e.Handled = true;
Debug.WriteLine("I'm in HomePage");
}
else if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
second option - subscribe to Windows.Phone.UI.Input.HardwareButtons.BackPressed when you enter the Page and unsubscribe when you leave the Page. Note that in this way there are some pitfalls - you have to handle properly OnNavigatedTo, OnNavigatedFrom, Suspending and Resuming (more about Lifecycle here). Note also that the subscription should be done before others - for example NavigationHelper.
Some remarks - the above code should work, but it also depends on other circumstances:
if there is something other subscribed to BackPressed before (in App.xaml.cs) - remember that usually events are fired in order they were subscribed
check if you are using NavigationHelper - it also subscribes to BackPressed
remember not to subscribe multiple times
remember to allow the User to leave your HomePage

how to stop / pause geolocation on android

Im experimenting with flashbuilder 4.6 and am using this simple / bare-bones geolocation code I found online to do some testing as I try to learn more about it and how it might be used...
one thing I am curious to know is how to stop / interrupt the geolocation routine so that it STOPS polling for the location and waits for the user to 'start' the geolocation.
if I use clearInterval(interval); that can stop the loop I guess -- but geo2 continues to exist and use device resources, correct? what would the code look like to use a slideToggle to control it for example?
The geolocation code snippet Im experimenting with...
private function onMapReady(e:Event):void
{
if (Geolocation.isSupported)
{
var geo = new Geolocation();
geo.setRequestedUpdateInterval(100);
geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
}
else
{
trace("No geolocation support.");
}
}
private function geolocationUpdateHandler(event:GeolocationEvent):void
{
trace("lat:" + event.latitude.toString() + " - ");
trace("long:" + event.longitude.toString() + "° - ");
trace("Accuracy:" + event.horizontalAccuracy.toString() + " m");
}
If you want to stop reacting to polling updates, just remove the listener:
geo.removeEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
If you want to switch off polling completely, just nullify it:
geo = null;
(and make sure you also remove any listeners first)

Flash authoring environment strange Test Movie behavior (AS3)

I can't for the life of me figure out why this is happening. Let me describe what I'm experiencing.
I add everything dynamically via actionscript.
In the Flash authoring environment, when I test the movie, sometimes all of the movieclips on stage disappear and all I see is the color of the Stage.
The strange thing is that I can still rollover/rollout (I added trace statements to my rollover/rollout handlers).
I'm also tracing out the 'visible' and the 'alpha' property and visible=true and alpha=1.0 !!!
On thing that I am seeing is sometimes the rollover/rollout methods get called multiple times in quick succession. I.e. the method invocation order is rollover, rollout, rollover or rollout, rollover, rollout.
The actions that I have in my rollover and rollout methods are really simple. All they do is turn on/off other movieclips...imagine a map...when you rollover an icon, a path shows up on the map and when your rolloff, the path goes away.
However, if I adjust the window of the test movie window, everything appears again!
The crazy thing is that when I publish it, this behavior doesn't happen in the browser or as an app!
What's going on? Could it be a memory thing with the authoring environment?
Posting some code here:
private function rollOverUserListener ( e:MouseEvent ) {
trace(">>>>>>>> rollOverUserListener() e.currentTarget.name : " + e.currentTarget.name);
trace("e.currentTarget.alpha: " + e.currentTarget.alpha);
trace("e.currentTarget.visible: " + e.currentTarget.visible);
e.currentTarget.rollOverAction(); //just scales the icon a little
//fade up/down the appropriate path
worldMap.resetPaths(); //turns off all the paths
for (var i=0; i<users.length; i++){
if ( e.currentTarget == users[i] ) { //highlight the right path
worldMap.highlightPath(i);
}
}
}
private function rollOutUserListener ( e:MouseEvent ) {
trace("<<<<<<<< rollOutUserListener() e.currentTarget.name : " + e.currentTarget.name);
e.currentTarget.rollOutAction(); //scales down the icon to normal
worldMap.resetPaths();
}
I don't think it's efficient to try and solve this problem via posting the code you did.
But, my guess is that the difference in behavior that you are seeing is due to the flash player version.
CS5 or whatever version you have of flash, comes with the latest player at that time. But the flash player is constantly being upgraded, so when you are in your browser -- you most likely have the latest flash player. That could account for the differences you are seeing.
However, the code above doesn't help to much without seeing the highlightPaths and resetPaths functions. I see that you have a trace, but right after that -- there's code executed that could potentially easily change the state of anything you traced before rendering the frame.
Stick some traces after that code to see if you get what you expect.
Are you using any libraries that might have features only supported by a newer flash player ?
private function rollOverUserListener ( e:MouseEvent ) {
trace(">>>>>>>> rollOverUserListener() e.currentTarget.name : " + e.currentTarget.name);
trace("e.currentTarget.alpha: " + e.currentTarget.alpha);
trace("e.currentTarget.visible: " + e.currentTarget.visible);
e.currentTarget.rollOverAction(); //just scales the icon a little
//fade up/down the appropriate path
worldMap.resetPaths(); //turns off all the paths
for (var i=0; i<users.length; i++){
if ( e.currentTarget == users[i] ) { //highlight the right path
worldMap.highlightPath(i);
}
}
}
private function rollOutUserListener ( e:MouseEvent ) {
trace("<<<<<<<< rollOutUserListener() e.currentTarget.name : " + e.currentTarget.name);
e.currentTarget.rollOutAction(); //scales down the icon to normal
worldMap.resetPaths();
}