Android Tutorial JumpingSmiley - GameView example III

Status
Not open for further replies.
This is another example of GameView: GameView - Create 2D Android games - Part I

This is a simple "jumping" game where the user controls the movement by tilting the device:

SS-2013-02-07_18.17.28.png


There are two types of objects: Smiley - the main object and Brick which represents a single brick.

When the smiley moves upwards the background moves downwards. Bricks that go out of the screen are removed. A new brick is added instead of each removed brick.

Some of the bricks are moving and some of the bricks shrink when the smiley bounces on them.

All the sizes are scaled based on the device screen size (using percentage units).

Currently the game never ends. You can change it by modifying Smiley.Tick sub.

I think that this example is simpler than the Asteroids example as there are less "moving parts".
 

Attachments

  • JumpingSmiley.zip
    27.7 KB · Views: 1,459
Last edited:

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
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
 

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.
Top