Android Accelerometer For Gaming - android

I'm designing a game for Android and I would like to use the accelerometer for some aspects of control. Has anyone come across a tutorial or example for something like this?

AndEngine supports easy access to the acelerometer
You call this method to enable the Accelerometer with a listener:
this.enableAccelerometerSensor(this);
and this is how you react on changes of the accelerometer:
#Override
public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) {
this.mPhysicsWorld.setGravity(new Vector2(pAccelerometerData.getY(), pAccelerometerData.getX()));
}
(Taken from: http://code.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/PhysicsExample.java )
Best Regards,
Nicolas

I would recommend you to checkout this open sourced marble game. at google code.

Related

Haxe Help - Manipulating Android Back Button Action

Basically, I use Stencyl engine to make games. The engine uses Haxe and doesn't support everything that Haxe supports.
I want to manipulate he android 'back button' press. Stencyl supports code mode where I can write a haxe code. I wanted to overwrite android's default back button press. When player is playing the game, if he press back button, the game goes to background. Instead, I want the level to restart when backbutton is pressed. Can this be accomplished with any available source for Haxe?
I tried searching for any code help but can't find one. That's why messaging here. Appreciate any help.
P.S: Stencyl developer may not be a real developer for you. If that's the case, I'm not a developer. I'm just someone who uses all the resources to achieve what I want. So please avoid such topics which isn't going to help anybody.
You could try below code
Lib.current.stage.addEventListener(openfl.events.KeyboardEvent.KEY_UP, checkKeypress);
...
private function checkKeypress(e:openfl.events.KeyboardEvent):Void
{
switch (e.keyCode)
{
case openfl.ui.Keyboard.ESCAPE:
e.stopImmediatePropagation();
restartLevel();
}
}
private function restartLevel():Void
{
//your code to restart level here
}

Taking Screenshots Using Qt C++ on Android

thanks for checking my question out!
I'm currently working on a project using Qt C++, which is designed to be multi-platform. I'm a bit of a newcoming to it, so I've been asked to set up the ability to take screenshots from within the menu structure, and I'm having issues with the Android version of the companion app.
As a quick overview, it's a bit of software that send the content of a host PC's screen to our app, and I've been able to take screenshots on the Windows version just fine, using QScreen and QPixmap, like so:
overlaywindow.cpp
{
QPixmap screenSnapData = screenGrab->currentBackground();
}
screenGrabber.cpp
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
}
Unfortunately, Android seems to reject QScreen, and with most suggestions from past Google searches suggesting the now-deprecated QPixmap::grab(), I've gotten a little stuck.
What luck I have had is within the code for the menu itself, and QWidget, but that isn't without issue, of course!
QFile doubleCheckFile("/storage/emulated/0/Pictures/Testing/checking.png");
doubleCheckFile.open(QIODevice::ReadWrite);
QPixmap checkingPixmap = QWidget::grab();
checkingPixmap.save(&doubleCheckFile);
doubleCheckFile.close();
This code does take a screenshot, but only of the button strip currently implemented, and not for the whole screen. I've also taken a 'screenshot' of just a white box with the screen's dimensions by using:
QDesktopWidget dw;
QWidget *screen=dw.screen();
QPixmap checkingPixmap = screen->grab();
Would anyone know of whether there was an alternative to using QScreen to take a screenshot in Android, or whether there's a specific way to get it working as compared to Windows? Or would QWidget be the right track? Any help's greatly appreciated!
as i can read in Qt doc : In your screenGrabber.cpp :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
replace with :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( 0 ); // as 0 is the id of main screen
If you want to take a screenshot of your own widget, you can use the method QWidget::render (Qt Doc):
QPixmap pixmap(widget->size());
widget->render(&pixmap);
If you want to take a screenshot of another app/widget than your app, you should use the Android API...

Xamarin Forms Custom Renderer for Android not displaying

I am trying to render a checkbox in a Xamarin Forms app. There is nothing rendered at runtime, as far as I can tell the renderer is not even getting called.
Does anyone understand what I am missing or doing incorrectly?
Here is my class in Forms:
public class LegalCheckbox : View
{
public LegalCheckbox ()
{
}
}
And my custom renderer class in Droid:
public class CheckBoxRenderer : ViewRenderer<LegalCheckbox, CheckBox>
{
protected override void OnElementChanged (ElementChangedEventArgs<LegalCheckbox> e)
{
base.OnElementChanged (e);
CheckBox control = new Android.Widget.CheckBox(this.Context);
control.Checked = false;
control.Text = "I agree to terms";
control.SetTextColor (Android.Graphics.Color.Rgb (60, 60, 60));
this.SetNativeControl(control);
}
}
Along with the Assembly Directive:
[assembly: ExportRenderer(typeof(demo.LegalCheckbox), typeof(demo.Droid.CheckBoxRenderer))]
Took your code and fired up a new project with it. The code appears to function fine.
Only thin I can think that might be causing you an issue is the location of you assembly attribute. I typically place them just above the namespace declaration in the same file as my renderer.
I threw what I created up on my github maybe you can spot the difference.
https://github.com/DavidStrickland0/Xamarin-Forms-Samples/tree/master/RendererDemo
#Thibault D.
Xlabs isn't a bad project but its basically just all the code the opensource community came up with during the first year or so of Xamarin.Forms life. Its not really "Their Labs projects" and considering how much of it is marked up with Alpha Beta and the number of bugs in their issues page it's probably best not to imply that the Xamarin company has anything to do with it.
I am not sure if that is the issue but it would make more sense to me if your LegalCheckbox would inherit from a InputView rather than View.
Also, even if Xamarin.Forms does not have a Checkbox control you can still have a look at their "Labs" project here:
https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Checkbox-Control
(And I can actually see that they inherit from View...)

Xamarin Android Google Map v2 SetOnCameraChangeListener Method

I am working on android map app in xamarin android. I want to handle the zoom event of map. Can anybody tell me how can I do this in xamarin android using map.SetOnCameraChangeListener ..
Regards
This is a bit late of an answer, but this really helped me. Should have everything you need.
http://pastebin.com/dgdiDk2N
Basically you need to implement the interface:
public class MapTab : Fragment, GoogleMap.IOnCameraChangeListener
Then you can set the listener as such:
map.SetOnCameraChangeListener (this);
And you will also need to add the method OnCameraChange:
public async void OnCameraChange (CameraPosition cameraPos)
{
//Do your things here when the camera updates
}

Andengine, can't find a way to work with tilting/accelerometer

I saw online this code used a lot:
public void onAccelerometerChanged(final AccelerometerData myAccelerometerData) {)
When I try to use it, eclipse will not recognize the AccelerometerData class.
I'm having a hard time:
Detecting tilt.
Using it to change the worlds physics with box2d.
It would help me if anyone could show me ways of detecting tilting and using it.
Thank you.
You can see this code used in the PhysicsExample where it is used to change the center of gravity.
You must use the same code branch as the one in the example you have found. Notice that I linked GLES2-AnchorCenter branch version of the PhysicsExample. This branch is the newest. There is no AccelerometerData class. It has been renamed to AccelerationData.
Tilting (phone orientation) can be detected in a similar fashion. You have to call the following methods in your Activity and pass the correct listener.
protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener) {
return this.mEngine.enableOrientationSensor(this, pOrientationListener);
}
protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener, final OrientationSensorOptions pLocationSensorOptions) {
return this.mEngine.enableOrientationSensor(this, pOrientationListener, pLocationSensorOptions);
}

Categories

Resources