Java and LibGDX Framework count phone steps?









up vote
0
down vote

favorite












I need to count user step in my game to move player character.
My player should move while someone is walking, but after I use System.out.print on numstep its still zero.
How can i count my step in Java and the LibGDX Framework?



 public class PlayerBros extends Game 

public int step=0;

public class AndroidLauncher extends AndroidApplication implements SensorEventListener,StepListener

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
accel = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
simpleStepDetector = new StepDetector();
simpleStepDetector.registerListener(this);

sensorManager.registerListener(AndroidLauncher.this, accel, SensorManager.SENSOR_DELAY_FASTEST);
config = new AndroidApplicationConfiguration();
playerBros=new PlayerBros();
numSteps = playerBros.step;
initialize(playerBros, config);


@Override
public void onAccuracyChanged(Sensor sensor, int accuracy)


@Override
public void onSensorChanged(SensorEvent event)
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
simpleStepDetector.updateAccel(
event.timestamp, event.values[0], event.values[1], event.values[2]);
System.out.print("AndroidLauncher: "+numSteps);



@Override
public void step(long timeNs)
numSteps++;



}
public class PlayScreen implements Screen
private PlayerBros game;

public void handleInput(float dt)
player.b2body.applyLinearImpulse(new Vector2(game.step,y), player.b2body.getWorldCenter(), true);
hud.marioLabel.setText(" "+game.step);
System.out.print("PlayScreen: "+game.step);


public void update(float dt)
handleInput(dt);












share|improve this question



















  • 2




    You would have to make it yourself. In the Android module, use something like this gadgetsaint.com/android/create-pedometer-step-counter-android in order to make the step counter.
    – Ryan_DS
    Nov 12 at 0:11










  • I have followed that tutorial and now I want to apply my step to my game character to make it move. But for some reason my game character wont move and I think I am passing my step from AndroidLauncher to PlayScreen wrong. Can someone help me?
    – David Ruland
    Nov 20 at 11:43











  • You need to provide context with code, preferably within the post itself instead of through links, and actions you have taken to debug. Did you try using System.out to verify the steps number? How about a System.out on every step?
    – Ryan_DS
    Nov 26 at 3:11















up vote
0
down vote

favorite












I need to count user step in my game to move player character.
My player should move while someone is walking, but after I use System.out.print on numstep its still zero.
How can i count my step in Java and the LibGDX Framework?



 public class PlayerBros extends Game 

public int step=0;

public class AndroidLauncher extends AndroidApplication implements SensorEventListener,StepListener

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
accel = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
simpleStepDetector = new StepDetector();
simpleStepDetector.registerListener(this);

sensorManager.registerListener(AndroidLauncher.this, accel, SensorManager.SENSOR_DELAY_FASTEST);
config = new AndroidApplicationConfiguration();
playerBros=new PlayerBros();
numSteps = playerBros.step;
initialize(playerBros, config);


@Override
public void onAccuracyChanged(Sensor sensor, int accuracy)


@Override
public void onSensorChanged(SensorEvent event)
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
simpleStepDetector.updateAccel(
event.timestamp, event.values[0], event.values[1], event.values[2]);
System.out.print("AndroidLauncher: "+numSteps);



@Override
public void step(long timeNs)
numSteps++;



}
public class PlayScreen implements Screen
private PlayerBros game;

public void handleInput(float dt)
player.b2body.applyLinearImpulse(new Vector2(game.step,y), player.b2body.getWorldCenter(), true);
hud.marioLabel.setText(" "+game.step);
System.out.print("PlayScreen: "+game.step);


public void update(float dt)
handleInput(dt);












share|improve this question



















  • 2




    You would have to make it yourself. In the Android module, use something like this gadgetsaint.com/android/create-pedometer-step-counter-android in order to make the step counter.
    – Ryan_DS
    Nov 12 at 0:11










  • I have followed that tutorial and now I want to apply my step to my game character to make it move. But for some reason my game character wont move and I think I am passing my step from AndroidLauncher to PlayScreen wrong. Can someone help me?
    – David Ruland
    Nov 20 at 11:43











  • You need to provide context with code, preferably within the post itself instead of through links, and actions you have taken to debug. Did you try using System.out to verify the steps number? How about a System.out on every step?
    – Ryan_DS
    Nov 26 at 3:11













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need to count user step in my game to move player character.
My player should move while someone is walking, but after I use System.out.print on numstep its still zero.
How can i count my step in Java and the LibGDX Framework?



 public class PlayerBros extends Game 

public int step=0;

public class AndroidLauncher extends AndroidApplication implements SensorEventListener,StepListener

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
accel = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
simpleStepDetector = new StepDetector();
simpleStepDetector.registerListener(this);

sensorManager.registerListener(AndroidLauncher.this, accel, SensorManager.SENSOR_DELAY_FASTEST);
config = new AndroidApplicationConfiguration();
playerBros=new PlayerBros();
numSteps = playerBros.step;
initialize(playerBros, config);


@Override
public void onAccuracyChanged(Sensor sensor, int accuracy)


@Override
public void onSensorChanged(SensorEvent event)
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
simpleStepDetector.updateAccel(
event.timestamp, event.values[0], event.values[1], event.values[2]);
System.out.print("AndroidLauncher: "+numSteps);



@Override
public void step(long timeNs)
numSteps++;



}
public class PlayScreen implements Screen
private PlayerBros game;

public void handleInput(float dt)
player.b2body.applyLinearImpulse(new Vector2(game.step,y), player.b2body.getWorldCenter(), true);
hud.marioLabel.setText(" "+game.step);
System.out.print("PlayScreen: "+game.step);


public void update(float dt)
handleInput(dt);












share|improve this question















I need to count user step in my game to move player character.
My player should move while someone is walking, but after I use System.out.print on numstep its still zero.
How can i count my step in Java and the LibGDX Framework?



 public class PlayerBros extends Game 

public int step=0;

public class AndroidLauncher extends AndroidApplication implements SensorEventListener,StepListener

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
accel = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
simpleStepDetector = new StepDetector();
simpleStepDetector.registerListener(this);

sensorManager.registerListener(AndroidLauncher.this, accel, SensorManager.SENSOR_DELAY_FASTEST);
config = new AndroidApplicationConfiguration();
playerBros=new PlayerBros();
numSteps = playerBros.step;
initialize(playerBros, config);


@Override
public void onAccuracyChanged(Sensor sensor, int accuracy)


@Override
public void onSensorChanged(SensorEvent event)
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
simpleStepDetector.updateAccel(
event.timestamp, event.values[0], event.values[1], event.values[2]);
System.out.print("AndroidLauncher: "+numSteps);



@Override
public void step(long timeNs)
numSteps++;



}
public class PlayScreen implements Screen
private PlayerBros game;

public void handleInput(float dt)
player.b2body.applyLinearImpulse(new Vector2(game.step,y), player.b2body.getWorldCenter(), true);
hud.marioLabel.setText(" "+game.step);
System.out.print("PlayScreen: "+game.step);


public void update(float dt)
handleInput(dt);









java libgdx step






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 at 15:59

























asked Nov 12 at 0:07









David Ruland

84




84







  • 2




    You would have to make it yourself. In the Android module, use something like this gadgetsaint.com/android/create-pedometer-step-counter-android in order to make the step counter.
    – Ryan_DS
    Nov 12 at 0:11










  • I have followed that tutorial and now I want to apply my step to my game character to make it move. But for some reason my game character wont move and I think I am passing my step from AndroidLauncher to PlayScreen wrong. Can someone help me?
    – David Ruland
    Nov 20 at 11:43











  • You need to provide context with code, preferably within the post itself instead of through links, and actions you have taken to debug. Did you try using System.out to verify the steps number? How about a System.out on every step?
    – Ryan_DS
    Nov 26 at 3:11













  • 2




    You would have to make it yourself. In the Android module, use something like this gadgetsaint.com/android/create-pedometer-step-counter-android in order to make the step counter.
    – Ryan_DS
    Nov 12 at 0:11










  • I have followed that tutorial and now I want to apply my step to my game character to make it move. But for some reason my game character wont move and I think I am passing my step from AndroidLauncher to PlayScreen wrong. Can someone help me?
    – David Ruland
    Nov 20 at 11:43











  • You need to provide context with code, preferably within the post itself instead of through links, and actions you have taken to debug. Did you try using System.out to verify the steps number? How about a System.out on every step?
    – Ryan_DS
    Nov 26 at 3:11








2




2




You would have to make it yourself. In the Android module, use something like this gadgetsaint.com/android/create-pedometer-step-counter-android in order to make the step counter.
– Ryan_DS
Nov 12 at 0:11




You would have to make it yourself. In the Android module, use something like this gadgetsaint.com/android/create-pedometer-step-counter-android in order to make the step counter.
– Ryan_DS
Nov 12 at 0:11












I have followed that tutorial and now I want to apply my step to my game character to make it move. But for some reason my game character wont move and I think I am passing my step from AndroidLauncher to PlayScreen wrong. Can someone help me?
– David Ruland
Nov 20 at 11:43





I have followed that tutorial and now I want to apply my step to my game character to make it move. But for some reason my game character wont move and I think I am passing my step from AndroidLauncher to PlayScreen wrong. Can someone help me?
– David Ruland
Nov 20 at 11:43













You need to provide context with code, preferably within the post itself instead of through links, and actions you have taken to debug. Did you try using System.out to verify the steps number? How about a System.out on every step?
– Ryan_DS
Nov 26 at 3:11





You need to provide context with code, preferably within the post itself instead of through links, and actions you have taken to debug. Did you try using System.out to verify the steps number? How about a System.out on every step?
– Ryan_DS
Nov 26 at 3:11


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254498%2fjava-and-libgdx-framework-count-phone-steps%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254498%2fjava-and-libgdx-framework-count-phone-steps%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線