Android Tutorial JumpingSmiley - GameView example III

Status
Not open for further replies.

Douglas Farias

Expert
Licensed User
Longtime 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:

Douglas Farias

Expert
Licensed User
Longtime 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
 

wonder

Expert
Licensed User
Longtime User

Douglas Farias

Expert
Licensed User
Longtime 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.

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?
B4X:
Private Sub Sensor_SensorChanged (Values() As Float)
    animator.vx = -PerXToCurrent(Max(-30, Min(30, Values(2))) / 10)
End Sub

how to put a left and right button pressed on this code?
 

Douglas Farias

Expert
Licensed User
Longtime 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
 

wonder

Expert
Licensed User
Longtime 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:
B4X:
Sub Clamp(minimum As Double, maximum As Double, value As Double)
    Return Max(minimum, Min(maximum, value))
End Sub

B4X:
Private Sub Sensor_SensorChanged (Values() As Float)
    animator.vx = -PerXToCurrent(Clamp(-30, 30, Values(2)) / 10)
End Sub
 

Douglas Farias

Expert
Licensed User
Longtime User


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
 

Douglas Farias

Expert
Licensed User
Longtime User
ok, thx erel, if you have a time can post a same game example with left and right buttons pls? without sensor.
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel i changed the code
TYPE_ORIENTATION to TYPE_ACCELEROMETER
and the

B4X:
Private Sub Sensor_SensorChanged (Values() As Float)
    animator.vx = -PerXToCurrent(Max(-30, Min(30, Values(2))))
End Sub
to
B4X:
Private Sub Sensor_SensorChanged (Values() As Float)
    animator.vx = -PerXToCurrent(Max(-30, Min(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?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…