Games any game profi please

ilan

Expert
Licensed User
Longtime User
i am trying to implement am arrow shoot in my game bt getting an error.

this is what i want to archive (http://www.iforce2d.net/b2dtut/sticky-projectiles)


i have this:

B4X:
'create arrow
    Dim chez As lgBox2DPolygonShape
    Dim vertex(4) As lgMathVector2
    vertex(0).Set(-1.4,0)
    vertex(1).Set(0,-0.1)
    vertex(2).Set(0.6,0)
    vertex(3).Set(0,0.1)
    chez.Set(vertex)
    'create body
    Dim fd As lgBox2DFixtureDef
    fd.shape = chez  
    fd.restitution = 0.2
    fd.Density = 1
    fd.friction = 0.5  
      
    Dim bd_def As lgBox2DBodyDef
    bd_def.type = World.BODYTYPE_Dynamic
    bd_def.position.set(PosCon.world2box2d(ScreenX,ScreenY,0,0).x,PosCon.world2box2d(ScreenX,ScreenY,0,0).y)
     Dim box2dbody As lgBox2DBody
    box2dbody = World.createBody(bd_def)
    box2dbody.createFixture(fd)
     chez.dispose
    Dim pointingDirection As lgMathVector2
    pointingDirection.Set(ScreenX,ScreenY)
  
    Dim flightDirection As lgMathVector2 = box2dbody.getLinearVelocityFromWorldPoint(box2dbody.WorldCenter)
    Dim flightSpeed As Float = flightDirection.nor '();//normalizes And returns length
    Dim lmath As lgMathVector2
    Dim dot As Float = lmath.dot(pointingDirection)
    Dim dragForceMagnitude As Float = (1 - Abs(dot)) * flightSpeed * flightSpeed * 1 * box2dbody.Mass

    Dim vec2 As lgMathVector2
    vec2.Set(-1.4,0)
    Dim arrowTailPosition As lgMathVector2 = box2dbody.getWorldPoint(vec2)
    Dim vec3 As lgMathVector2
    vec3.Set(dragForceMagnitude*(-flightDirection.x),dragForceMagnitude*(-flightDirection.y))
    box2dbody.applyForce(vec3, arrowTailPosition,True)

i dont know how to implement the b2Dot method in b4a.
i have no (vec2,vec2) option i have only a 1 vec2 option.

i think it is a box2d function but in box2d for b4a there is no n2dot method.

the error i am getting is this:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
sensor listener setup
OGL renderer: Android Emulator OpenGL ES Translator (Intel(R) HD Graphics 4000)
OGL vendor: Google (Intel)
OGL version: OpenGL ES 2.0 (4.0.0 - Build 10.18.10.4358)
OGL extensions: GL_EXT_debug_marker GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_texture_npot GL_OES_rgb8_rgba8ANDROID_EMU_CHECKSUM_HELPER_v1
framebuffer: (5, 6, 5, 0)
depthbuffer: (16)
stencilbuffer: (0)
samples: (0)
coverage sampling: (false)
Managed meshes/app: { }
Managed textures/app: { }
Managed shaders/app: { }
Managed buffers/app: { }
main_ip_touchdown (java line: 799)
java.lang.NumberFormatException: For input string: "[0.0:0.0]"
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1306)
at java.lang.Double.parseDouble(Double.java:547)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:646)
at www.sagital.tmi.main._ip_touchdown(main.java:799)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.libgdx.input.lgInputProcessor$1.touchDown(SourceFile:81)
at com.badlogic.gdx.InputMultiplexer.touchDown(SourceFile:93)
at com.badlogic.gdx.backends.android.AndroidInput.a(SourceFile:387)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(SourceFile:448)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1553)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1253)
java.lang.NumberFormatException: For input string: "[0.0:0.0]"
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.app.Dialog.<init>(Dialog.java:121)
at android.app.AlertDialog.<init>(AlertDialog.java:200)
at android.app.AlertDialog$Builder.create(AlertDialog.java:1086)
at anywheresoftware.b4a.BA.ShowErrorMsgbox(BA.java:260)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:224)
at anywheresoftware.b4a.libgdx.input.lgInputProcessor$1.touchDown(SourceFile:81)
at com.badlogic.gdx.InputMultiplexer.touchDown(SourceFile:93)
at com.badlogic.gdx.backends.android.AndroidInput.a(SourceFile:387)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(SourceFile:448)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1553)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1253)
** Activity (main) Pause, UserClosed = true **
waiting for pause synchronization took too long; assuming deadlock and killing

i am sure i have not converted the code correctly but i am not sure how to do that. who can help me please?

thank you
 

melonZgz

Active Member
Licensed User
Longtime User
i am trying to implement am arrow shoot in my game bt getting an error.

this is what i want to archive (http://www.iforce2d.net/b2dtut/sticky-projectiles)


i have this:

B4X:
'create arrow
    Dim chez As lgBox2DPolygonShape
    Dim vertex(4) As lgMathVector2
    vertex(0).Set(-1.4,0)
    vertex(1).Set(0,-0.1)
    vertex(2).Set(0.6,0)
    vertex(3).Set(0,0.1)
    chez.Set(vertex)
    'create body
    Dim fd As lgBox2DFixtureDef
    fd.shape = chez 
    fd.restitution = 0.2
    fd.Density = 1
    fd.friction = 0.5 
     
    Dim bd_def As lgBox2DBodyDef
    bd_def.type = World.BODYTYPE_Dynamic
    bd_def.position.set(PosCon.world2box2d(ScreenX,ScreenY,0,0).x,PosCon.world2box2d(ScreenX,ScreenY,0,0).y)
     Dim box2dbody As lgBox2DBody
    box2dbody = World.createBody(bd_def)
    box2dbody.createFixture(fd)
     chez.dispose
    Dim pointingDirection As lgMathVector2
    pointingDirection.Set(ScreenX,ScreenY)
 
    Dim flightDirection As lgMathVector2 = box2dbody.getLinearVelocityFromWorldPoint(box2dbody.WorldCenter)
    Dim flightSpeed As Float = flightDirection.nor '();//normalizes And returns length
    Dim lmath As lgMathVector2
    Dim dot As Float = lmath.dot(pointingDirection)
    Dim dragForceMagnitude As Float = (1 - Abs(dot)) * flightSpeed * flightSpeed * 1 * box2dbody.Mass

    Dim vec2 As lgMathVector2
    vec2.Set(-1.4,0)
    Dim arrowTailPosition As lgMathVector2 = box2dbody.getWorldPoint(vec2)
    Dim vec3 As lgMathVector2
    vec3.Set(dragForceMagnitude*(-flightDirection.x),dragForceMagnitude*(-flightDirection.y))
    box2dbody.applyForce(vec3, arrowTailPosition,True)

i dont know how to implement the b2Dot method in b4a.
i have no (vec2,vec2) option i have only a 1 vec2 option.

i think it is a box2d function but in box2d for b4a there is no n2dot method.

the error i am getting is this:



i am sure i have not converted the code correctly but i am not sure how to do that. who can help me please?

thank you

the lgMathVector2 has a dot function, so you could write:
B4X:
dim dot as float = flightDirection.dot(pointingDirection)
 

ilan

Expert
Licensed User
Longtime User
thanks @melonZgz :)

i also found out the the normalize function returns a vector2 and not a float so i use now nor.len :)

i still have nt the result i want but i am getting closer
 

ilan

Expert
Licensed User
Longtime User
now i have another problem.

the arrow is a polygon with the center not in the middle

now when i want to raw a texture to it i have difficulties to find the position because the arrow rotates.

B4X:
        Batch.DrawTex5(arrowtx,pos.x-(vpW*0.05),pos.y-(vpH*0.01),vpW*0.05,vpH*0.01,vpW*0.1,vpH*0.02,1,1,PosCon.Rad2Angle(arr.Angle),0,0,67,11,False,False)

arrow.png


like this the texture is drawn correctly with the angle rotation but in the wrong place

if i move the texture left (...,pos.x-(vpW*0.075),...) the texture is draw not on the same place as the body when it rotates. only on angle 0 it draws correctly

any advices?
 

wonder

Expert
Licensed User
Longtime User
now when i want to raw a texture to it i have difficulties to find the position because the arrow rotates.
Why don't you just use transparency, so that the offset is nothing but a visual trick?
This way you can center the texture in the object.
upload_2017-10-3_8-4-37.png
 

ilan

Expert
Licensed User
Longtime User
Why don't you just use transparency, so that the offset is nothing but a visual trick?
This way you can center the texture in the object.
View attachment 60215

This is exactly what i did. But i thought its not the proper way :) (u can see in the gif that the arrow position is in the right place)
 

ilan

Expert
Licensed User
Longtime User
Wow! this looks great! Nice work Ilan!

This is just the beginning. It will be very very awesome with many features.

You will have a village where u train your mindians before you battle another tribe.

Every mindian has his own skills and u need to train him to become better befor u use him in a battle.

Every mindian will use a different weapon.

You will need to think carefully wich mindians to use in a battle. Should you pick the mindians that throws arrows? Or the one that throws stones?... so you will also need to use a good strategy to win all battles and become the strongest mindian tribe around.

it wont be easy to make this game but it will be very nice i hope :)

Btw the name of the game is

"The Mindians"
 

JordiCP

Expert
Licensed User
Longtime User
Very nice!! I'm not a gamer, but I find it really appealing!

BTW, "mindian" = "minion" + "indian" ? ;)
 

ilan

Expert
Licensed User
Longtime User
BTW, "mindian" = "minion" + "indian" ? ;)

You are smart :)
Yes thats correct mindian = minion + indian :)

Maybe sony will buy the rights and make a movie about it ... who knows...
 
Last edited:

ilan

Expert
Licensed User
Longtime User
Did you ever get round to writing that box2D + libgdx tutorial??? I'm interested in getting into box2d work.

The theory is very simple

You have a world and create bodies in this world. Then you apply forces to them and use libgdx to draw sprites to each body.

I have created a new youtube channel l, its called The B4X Guy but i had no time to add a tutorial until now. I will try to do it and start a series of box2d + libgdx.

I need to mention that i am no pro in this area so i maybe am not doing everything as written in the book but it works fine :)
 

andymc

Well-Known Member
Licensed User
Longtime User
haha! :) none of us are pros! I don't even know how to use texture atlases yet! I think I need to learn though because I'm getting performance issues with my invaders deluxe game on older devices and I think it comes down to using separate textures for everything.
 

ilan

Expert
Licensed User
Longtime User
haha! :) none of us are pros! I don't even know how to use texture atlases yet! I think I need to learn though because I'm getting performance issues with my invaders deluxe game on older devices and I think it comes down to using separate textures for everything.

@melonZgz really do his game very professional. He uses atlas and lots of own functions. He can give us a lot of advises.

Btw @Informatix has a lot examples how to use almost anything in libgdx and box2d so looking at his examples will make your life and mine much easier.

At the end its not that complicated we just need to try to learn always new stuff and not stick on what we already know
 

melonZgz

Active Member
Licensed User
Longtime User
now i have another problem.

the arrow is a polygon with the center not in the middle

now when i want to raw a texture to it i have difficulties to find the position because the arrow rotates.

B4X:
        Batch.DrawTex5(arrowtx,pos.x-(vpW*0.05),pos.y-(vpH*0.01),vpW*0.05,vpH*0.01,vpW*0.1,vpH*0.02,1,1,PosCon.Rad2Angle(arr.Angle),0,0,67,11,False,False)

View attachment 60207

like this the texture is drawn correctly with the angle rotation but in the wrong place

if i move the texture left (...,pos.x-(vpW*0.075),...) the texture is draw not on the same place as the body when it rotates. only on angle 0 it draws correctly

any advices?

If there isn't going to be any animation I prefer using lgsprite instead of lgtextureregion, and setting the origin of the sprite according to the origin of the body (made hith physicsBodyEditor)
 

ilan

Expert
Licensed User
Longtime User
If there isn't going to be any animation I prefer using lgsprite instead of lgtextureregion, and setting the origin of the sprite according to the origin of the body (made hith physicsBodyEditor)

thank you @melonZgz, i dont like using phsyicsBodyEditor. i preffer creating my bodies in tiled and load everything from there.

anyway what i did is i just resized the image and put more blank space to the right and it works :)

arrow.png


(note that there is a blank space in on the right of the arrow)
 

ilan

Expert
Licensed User
Longtime User
Top