Feb 7, 2013 Replies: 42 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: 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 JumpingSmiley.zip 27.7 KB · Views: 2,045 Last edited: Feb 9, 2016 Click to expand...
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: 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".
Erel B4X founder Staff member Licensed User Longtime User Mar 10, 2014 #22 Can you run the original example in Release mode and post the error message?
Douglas Farias Expert Licensed User Longtime User Mar 10, 2014 #23 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
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/
Erel B4X founder Staff member Licensed User Longtime User Mar 11, 2014 #24 Maybe this device doesn't have an accelerometer sensor.
Douglas Farias Expert Licensed User Longtime User Mar 11, 2014 #25 Sensors: Accelerometer, Geo-Magnetic
Douglas Farias Expert Licensed User Longtime User Feb 9, 2016 #26 @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
@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 Feb 9, 2016 #27 @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. Erel said: For new games it is recommended to use libGDX. See these tutorials: How to make games Introduction to the libGDX library Click to expand...
@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. Erel said: For new games it is recommended to use libGDX. See these tutorials: How to make games Introduction to the libGDX library Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Feb 9, 2016 #28 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.
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 Expert Licensed User Longtime User Feb 9, 2016 #29 Erel said: 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. Click to expand... 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(-30, Min(30, Values(2))) / 10) End Sub how to put a left and right button pressed on this code?
Erel said: 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. Click to expand... 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(-30, Min(30, Values(2))) / 10) End Sub how to put a left and right button pressed on this code?
Erel B4X founder Staff member Licensed User Longtime User Feb 10, 2016 #30 Try to change the rate to 3.
Douglas Farias Expert Licensed User Longtime User Feb 10, 2016 #31 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
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 Feb 10, 2016 #32 @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(-30, 30, Values(2)) / 10) End Sub
@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(-30, 30, Values(2)) / 10) End Sub
Erel B4X founder Staff member Licensed User Longtime User Feb 10, 2016 #33 You can test it with this example: https://www.b4x.com/android/forum/threads/orientation-and-accelerometer.6647/#content
You can test it with this example: https://www.b4x.com/android/forum/threads/orientation-and-accelerometer.6647/#content
Douglas Farias Expert Licensed User Longtime User Feb 10, 2016 #34 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
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
Erel B4X founder Staff member Licensed User Longtime User Feb 10, 2016 #37 Accelerometer sensor is less suitable for tilting detection.
Douglas Farias Expert Licensed User Longtime User Feb 10, 2016 #38 ok, thx erel, if you have a time can post a same game example with left and right buttons pls? without sensor.
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 Feb 11, 2016 #39 @Erel i changed the code TYPE_ORIENTATION to TYPE_ACCELEROMETER and the Code: Private Sub Sensor_SensorChanged (Values() As Float) animator.vx = -PerXToCurrent(Max(-30, Min(30, Values(2)))) End Sub to Code: 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?
@Erel i changed the code TYPE_ORIENTATION to TYPE_ACCELEROMETER and the Code: Private Sub Sensor_SensorChanged (Values() As Float) animator.vx = -PerXToCurrent(Max(-30, Min(30, Values(2)))) End Sub to Code: 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?
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2016 #40 As I previously wrote, calculating the tilt from the accelerometer sensor is much more complicated. 99% of the devices do have an orientation sensor...
As I previously wrote, calculating the tilt from the accelerometer sensor is much more complicated. 99% of the devices do have an orientation sensor...