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)
{
}
}
Related
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
}
});
I am building a Windows Phone 8.1 Silverlight App. I am able to use both the following registries:
Windows.Storage.ApplicationData.Current.LocalSettings;
IsolatedStorageSettings.ApplicationSettings;
What are the differeces between these two?
Which one is better?
The difference between Windows.Storage.ApplicationData.Current.LocalSettings and IsolatedStorageSettings.ApplicationSettingsis that the first one is the newer unified Windows Store App API whereas the latter is from the "old" Silverlight API.
New is not always better but I personally think you should go with the modern version here. Both work with Silverlight but if you ever have to migrate your code to WinRT you will save yourself some time since the IsolatedStorageSettings API does not work under WinRT.
There is huge difference in using both settings:
IsolatedStorageSettings works like a Dictionary and it's serialized and saved to IsolatedStorageFile:
IsolatedStorageSettings provide a convenient way to store user specific data as key-value pairs in a local IsolatedStorageFile.
Also note that IsolatedStorageSettings has to be saved - IsolatedStorageSettings.Save. After saving you will find a file __ApplicationSettings in your app's isolated storage.
ApplicationData.LocalSettings is an ApplicationDataContainer. Once you add there a value, it's automatically saved. It's model is conceptually equivalent to the Windows registry.
So they are totally different thing, and if you add key to one of above Settings then it won't appear automatically in second. Consider two buttons:
const string firstKey = "firstKey";
const string secondKey = "secondKey";
IsolatedStorageSettings isoSetting = IsolatedStorageSettings.ApplicationSettings;
ApplicationDataContainer localSetting = ApplicationData.Current.LocalSettings;
private void Button_Click(object sender, RoutedEventArgs e)
{
isoSetting.Add(firstKey, true);
localSetting.Values[secondKey] = false;
//isoSetting.Save(); // IsolatedStorageSettings have to be saved
Debug.WriteLine("Is first key in LocalSettings: {0}", localSetting.Values.ContainsKey(firstKey));
Debug.WriteLine("Is first key in ApplicationSettings: {0}", isoSetting.Contains(firstKey));
Debug.WriteLine("Is second key in LocalSettings: {0}", localSetting.Values.ContainsKey(secondKey));
Debug.WriteLine("Is second key in ApplicationSettings: {0}", isoSetting.Contains(secondKey));
}
private void Button_Click2(object sender, RoutedEventArgs e)
{
// run this button after app restart without clicking first button
// and saving IsoSettings
Debug.WriteLine("Is first key in LocalSettings: {0}", localSetting.Values.ContainsKey(firstKey));
Debug.WriteLine("Is first key in ApplicationSettings: {0}", isoSetting.Contains(firstKey));
Debug.WriteLine("Is second key in LocalSettings: {0}", localSetting.Values.ContainsKey(secondKey));
Debug.WriteLine("Is second key in ApplicationSettings: {0}", isoSetting.Contains(secondKey));
}
If I were writing a new app, then I would use new ApplicationData.LocalSettings API - it's newer and it will be much easier to port such an app to RunTime in the future, as WP8.1 RT doesn't support IsolatedStorageSettings.
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
I'm trying to use the C++ Accelerometer interface in the Windows::Devices::Sensors namespace on the Windows Phone 8. The code is very similar to a C# project I have that works, but I can't get the C++ event to fire like I can with my C# code.
My C++ code is a C# project with a C++ component, the C++ component just opens up the Accelerometer device for reading, and then tries to setup an event to fire whenever data is ready:
AccelerometerWrapper::AccelerometerWrapper() {
Accelerometer^ acc = Accelerometer::GetDefault();
accReading = acc->ReadingChanged::add( ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &AccelerometerWrapper::ReadingChanged));
}
void AccelerometerWrapper::ReadingChanged(Accelerometer^ sender, AccelerometerReadingChangedEventArgs^ e) {
...
}
Unfortunately, my ReadingChanged() function is never being called. I've looked around for a Start() method or somesuch but I can't find anything. I'm basing most of my knowledge off of the AccelerometerCPP example, but I can't actually test that as it is a generic WinRT (e.g. Windows 8, not Windows Phone 8) example, and my computer does not have an accelerometer. Everything compiles and runs, the event is just never triggered.
EDIT: I have successfully run a test to verify that I can manually call acc->GetCurrentReading(), so the accelerometer is working, it just seems to be the event that is not getting triggered.
Thank you in advance!
I'm not a C++ expert, but the new Accelerometer sensor works on my machine using C#.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var accelerometer = Accelerometer.GetDefault();
if (accelerometer != null)
{
accelerometer.ReadingChanged += accelerometer_ReadingChanged;
}
}
void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
Debug.WriteLine(args.Reading.AccelerationX + ", " + args.Reading.AccelerationY + "," + args.Reading.AccelerationZ);
}
When we run that code snippet we can see the following expected output:
Just a guess for C++, do you need to cache the Accelerometer instance somewhere instead of letting it go out of scope?
My team is working on a team project aplication. At the moment, we need an event handler to check the connection status (if it's on/off).
I had big hopes in the System.Net.NetworkInformation Namespace, but unfortunately most important things aren't supported in wp8.
Can anyone help me with it a bit?
Edit 1#
It seems, I didn't specifed my problem well.
I'm using Mvvm light expresion, and it does not support that namespace or at least I can't add it.
I'm a newbie in using VS and c# atm, mayby I'm doing someting wrong, but simply when im trying to add the refernce to my project it does not list.
I haven't tried the System.Net.NetworkInformation namespace on WP8. But the new WP8 Windows.Networking.Connectivity Windows Phone Runtime namespace works just fine.
Use Windows.Networking.Connectivity.NetworkInformation.NetworkStatusChanged to know when network conditions change and use Microsoft.Phone.Net.NetworkInformation.NetworkInterface properties or Windows.Networking.Connectivity.NetworkInformation properties to see what's up.
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
PrintNetworkStatus();
NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
}
void NetworkInformation_NetworkStatusChanged(object sender)
{
PrintNetworkStatus();
}
private void PrintNetworkStatus()
{
Dispatcher.BeginInvoke(() =>
MessageBox.Show(NetworkInterface.NetworkInterfaceType +
Environment.NewLine +
NetworkInterface.GetIsNetworkAvailable()));
}
When I test this code snippet on my WP8 Lumia 920 it works as expected. On startup when my phone is on WiFi only I see the following MessageBox:
And once I shutdown my WiFI router and the WiFi connection on the phone is lost I see the following MessageBox:
Try this:
bool isNetwork=NetworkInterface.GetIsNetworkAvailable();
if(!isNetwork)
{
//proceed with your code
}
In App.xaml.cs, create a property like below
/// <summary>
/// check if network is available
/// </summary>
public bool IsNetworkAvailable
{
get
{
return NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None;
}
}
And you can use this property anywhere in your project as in below code
if (((App) Application.Current).IsNetworkAvailable)
{
//Lines of Code
}
else
{
MessageBox.Show("Not Connected to Network!", "Checking Connection!",
MessageBoxButton.OK);
}