Android Tutorial JumpingSmiley - GameView example III

Discussion in 'Tutorials & Examples' started by Erel, Feb 7, 2013.

Thread Status:
Not open for further replies.
  1. Douglas Farias

    Douglas Farias Expert Licensed User

    yes i dont know why =(
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you run the original example in Release mode and post the error message?
     
  3. Douglas Farias

    Douglas Farias Expert Licensed User

    i dont know creat a logs on my real device in release
    but i go write the erros

    an error has occured in sub:
    java.lang.
    illegalargumentexception
    continue yes or no?


    an error has occured in sub:
    smiley_startsensor
    java line 90
    continue yes or no?

    an error has occured in sub:
    smyle_tick
    line 105



    this is my device

    http://www.gsmarc.com/samsung/star-trios/
     
    Last edited: Mar 10, 2014
  4. Erel

    Erel Administrator Staff Member Licensed User

    Maybe this device doesn't have an accelerometer sensor.
     
  5. Douglas Farias

    Douglas Farias Expert Licensed User

  6. Douglas Farias

    Douglas Farias Expert Licensed User

    @Erel sorry to post here on old post.
    but i have a question about, i m trying to run your sample. my device is the Galaxy J2 and this have accelerometer but the smyle is not moving on the screen.
    i m tryed change sensor.TYPE_ORIENTATION to TYPE_ACCELEROMETER or TYPE_GYROSCOPE but not move too.

    the gv.IsHardwareAccelerated its true too.
    any error on my device i think.

    what can is this error?

    tryed the sample, without changes
     
  7. wonder

    wonder Expert Licensed User

    @Douglas Farias, not to disregard Erel's work, but this library is really outdated.
    Back in the day, I was using it for Project Ryu and after 3 months of development I had to rewrite the whole engine in LibGDX due to critical performance issues.
    Please beware and reconsider your choices.

     
  8. Erel

    Erel Administrator Staff Member Licensed User

    This library was indeed implemented before libGDX was available.

    I've uploaded a new version to the first post, it will fix this issue.

    For some reason the orientation sensor doesn't fire when the rate is set to 0.
     
    Douglas Farias likes this.
  9. Douglas Farias

    Douglas Farias Expert Licensed User

    thx @Erel but still not working.

    i need use this game sample to work on a simple game.
    its hard to change the moviments to buttons?

    the moviment its here? right?
    Code:
    Private Sub Sensor_SensorChanged (Values() As Float)
        animator.vx = -
    PerXToCurrent(Max(-30Min(30, Values(2))) / 10)
    End Sub
    how to put a left and right button pressed on this code?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Try to change the rate to 3.
     
  11. Douglas Farias

    Douglas Farias Expert Licensed User

    0,1,2,3 too, i think its a problem with sensor(lib). tested with 3 devices
    tested the libgdx (Sensors.b4a) example and this works.
    the problem its the sensor of phone lib i think or the game code
     
  12. wonder

    wonder Expert Licensed User

    @Douglas Farias, the Max(Min(value)) function is called a "Clamp" function. You're going to use it a lot when doing videogames, so here's a suggestion:
    Code:
    Sub Clamp(minimum As Double, maximum As Double, value As Double)
        
    Return Max(minimum, Min(maximum, value))
    End Sub
    Code:
    Private Sub Sensor_SensorChanged (Values() As Float)
        animator.vx = -
    PerXToCurrent(Clamp(-3030, Values(2)) / 10)
    End Sub
    :)
     
  13. Erel

    Erel Administrator Staff Member Licensed User

  14. Douglas Farias

    Douglas Farias Expert Licensed User

    12666388_1107201072643441_1045021448_n.jpg

    Really only accelerometer are suported on this device.

    i m tryed change the code to
    sensor.Initialize2(sensor.TYPE_ACCELEROMETER, 3)
    (0,1,2,3)
    but the smiley move to left only, i can tilt my device to right but the smiley still moving to left = tilt its ignored

    need make changes on the code to replace TYPE_ORIENTATION to TYPE_ACCELEROMETER?

    the example works fine
    https://www.b4x.com/android/forum/threads/orientation-and-accelerometer.6647/#content

    if i tilt my device to left i got
    x = negative values
    if i put my device centered x = 0
    and if i tilt my device to right i got positive values on x


    but on game example the smiley still moving to left and dont move to another position
    tilt its ignored
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    Is this a real device?
     
  16. Douglas Farias

    Douglas Farias Expert Licensed User

    yes galaxy j2
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Accelerometer sensor is less suitable for tilting detection.
     
  18. Douglas Farias

    Douglas Farias Expert Licensed User

    ok, thx erel, if you have a time can post a same game example with left and right buttons pls? without sensor.
     
  19. Douglas Farias

    Douglas Farias Expert Licensed User

    @Erel i changed the code
    TYPE_ORIENTATION to TYPE_ACCELEROMETER
    and the

    Code:
    Private Sub Sensor_SensorChanged (Values() As Float)
        animator.vx = -
    PerXToCurrent(Max(-30Min(30, Values(2))))
    End Sub
    to
    Code:
    Private Sub Sensor_SensorChanged (Values() As Float)
        animator.vx = -
    PerXToCurrent(Max(-30Min(30, Values(0))))
    End Sub
    2 to 0 and now its working here on my device.
    now the question.
    the jumpingsmiley example works for u with Values(2)
    and for me with Values(0)
    this is not a fix value for all devices?

    the jumpingsmiley example here dont work, i need to change this 2 to 0 to work
    i dont have more devices to test here, but i think this is working for u with (2) original sample value.

    how can i make for work on all devices, have a fix value?
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    As I previously wrote, calculating the tilt from the accelerometer sensor is much more complicated.

    99% of the devices do have an orientation sensor...
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice