B4A Library libGDX - Game Engine

Informatix

Expert
Licensed User
Walter may testify that I was very reluctant to include the ShaderProgram class in libGDX because shader programs are mainly used in 3D, are complex to write and to use and I'm not an expert in this matter. On the other hand, most of the Wow! effects nowadays are made with these shader programs and everybody wants to include them in his/her application, so I don't want to prevent you from being a fashionista. ;) But don't count on me to explain anything about this. I prefer to explain how to do traditional effects that use a lot less CPU and GPU. It doesn't seem to me that the games were dull and ugly before OpenGL 2!

There's a tutorial (written by someone else) for the ShaderProgram demo. The link is given at the beginning of the code.
 
Last edited:

Laurent95

Active Member
Licensed User
.../ On the other hand, most of the Wow! effects nowadays are made with these shader programs and everybody wants to include them in his/her application, so I don't want to prevent you from being a fashionista. ;)/...... It doesn't seem to me that the games were dull and ugly before OpenGL 2!

There's a tutorial (written by someone else) for the ShaderProgram demo. The link is given at the beginning of the code.
Hahahahaha no worries about it, frankly speaking in regards my age i'm not ready to become a fashionista, or a fashion victim ;)
But as you told right in your tuts before, we need to adapt our way to program and think about.
Me also, i was a programer on basis languages like assembler many time ago.
But that's the past and now people want more and more, and unfortunatly we aren't born named Iwatani :)

No worries and thank you for the indication about the link.
But link don't work
 
Last edited:

fanfalveto

Active Member
Licensed User
this is incredible. thank you very much. I'm trying to make a game, very simple, based on a couple of examples. but? how I can make the effect of example Particles fill the screen or move around it? and how I can see the file .p?
Thanks and very good work. this library in itself is an infinite source of possibilities
 

fanfalveto

Active Member
Licensed User
about move efect :
B4X:
Effect.SetPosition(Rnd(0,lGdx.Graphics.Width), Rnd(0,lGdx.Graphics.Height ))
,i ask and i answer myself.
only then .p and fill screen with effect.
:)
 

Informatix

Expert
Licensed User
how I can make the effect of example Particles fill the screen or move around it? and how I can see the file .p?
The file .p is produced by the Particle editor and the size of particles is defined with this editor. Please read the chapter devoted to particles in the tutorial.
 

fanfalveto

Active Member
Licensed User
In the example Scn2D Drag'n'Drop,
B4X:
Atlas.InitializeWithFile("atlas/dragdrop.pack")
then
B4X:
DogHouse.Initialize3(Atlas.FindRegion("doghouse"), "")
    Stage.AddActor(DogHouse)
please can you explain me how can localice it if in the .png are "house","family","dog","cat" and "doghouse". In the code not appears "dragdrop.png",then this is in "dragdrop.pack"?
 

Informatix

Expert
Licensed User
From the chapter "Texture Atlas" of the tutorial, about the texture packer:
"This tool stores the images in the atlas with their file name without extension."
 

fanfalveto

Active Member
Licensed User
Please this is copy of the drag and drop example,y only create "chori.pack",but if one item go to the wrong target,dissapears ,don´t return to the original position.
Can you help me?
this is the code and the files zip.
Thank you,and sorry if i´m heavy :-(
B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: Scn2D Drag'n'Drop
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
End Sub

Sub Globals
    Dim lGdx As LibGDX
    Dim GL As lgGL
    Dim Stage As lgScn2DStage
    Dim Atlas As lgTextureAtlas

    Dim aznar, bandera As lgScn2DImage
    Dim barcenas, chorizo As lgScn2DImage
    Dim DragAndDrop As lgScn2DDragAndDrop
    Dim DnDPayload As lgScn2DDragAndDropPayload
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Initializes libGDX
    lGdx.Initialize(False, "LG")
End Sub

Sub Activity_Resume
    'Informs libGDX of Resume events
    If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    'Informs libGDX of Pause events
    If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub LG_Create
    'Initializes the stage
    Stage.Initialize("")

    'Loads the texture atlas
    Atlas.InitializeWithFile("atlas/chori.pack")

    'Creates the actors
    bandera.Initialize3(Atlas.FindRegion("bandera"), "")
    Stage.AddActor(bandera)


    barcenas.Initialize3(Atlas.FindRegion("barcenas"), "")
    Stage.AddActor(barcenas)


    aznar.Initialize3(Atlas.FindRegion("aznar"), "")
    Stage.AddActor(aznar)
    aznar.InitializeWithDrawable(aznar.Drawable, "")
   
   

    chorizo.Initialize3(Atlas.FindRegion("chorizo"), "")
    Stage.AddActor(chorizo)
    chorizo.InitializeWithDrawable(chorizo.Drawable, "")


    'Sets the size and position of actors

    bandera.Height =25%y
    bandera.Width = 25%x
    bandera.X = 0%x
    bandera.Y = 0%y

    barcenas.Height =  25%y
    barcenas.Width =  25%x
    barcenas.X = 0%x
    barcenas.Y =  75%y

    aznar.Height =  25%y
    aznar.Width =  25%x
    aznar.X = 75%x
    aznar.Y = 75%y


    chorizo.Height = 25%y
    chorizo.Width = 25%x
    chorizo.X = 75%x
    chorizo.Y =  0%y
   


    'Sets the drag'n'drop sources and targets
    DragAndDrop.Initialize
    DragAndDrop.AddSource(aznar, "aznar")
    DragAndDrop.AddSource(chorizo, "chorizo")
    DragAndDrop.AddTarget(barcenas, "barcenas")
    DragAndDrop.AddTarget(bandera, "bandera")

End Sub

Sub LG_Resize(Width As Int, Height As Int)
    'Sets the stage viewport
    Stage.SetViewport(Width, Height, True)
End Sub

Sub LG_Render
    'Clears the screen
    GL.glClearColor(0, 0.7, 0, 1) 'Green
    GL.glClear(GL.GL10_COLOR_BUFFER_BIT)

    'Applies the actions to actors
    Stage.Act

    'Draws the actors
    Stage.Draw
End Sub

Sub LG_Pause
End Sub

Sub LG_Resume
End Sub

Sub LG_Dispose
    'Disposes all resources
    Stage.dispose
    Atlas.dispose
End Sub

Sub aznar_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the family actor invisible
    aznar.Visible = True

    'Sets the drag actor for the family
    DnDPayload.DragActor = aznar
    DragAndDrop.SetDragActorPosition(-aznar.Width, aznar.Height)
    Return DnDPayload
End Sub

Sub aznar_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the family actor visible
    aznar.Visible = True
End Sub

Sub chorizo_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the dog actor invisible
    chorizo.Visible = True

    'Sets the drag actor for the dog
    DnDPayload.DragActor = chorizo
    DragAndDrop.SetDragActorPosition(-chorizo.Width, chorizo.Height)
    Return DnDPayload
End Sub

Sub chorizo_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the dog actor visible
    chorizo.Visible = True
End Sub

Sub bandera_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped
    If Source=chorizo Then

            Return False
    Else 

        Return True

           
        End If

End Sub
Sub bandera_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
   
End Sub
Sub bandera_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = bandera.Y

    DragAndDrop.RemoveSource(Source)

End Sub

Sub barcenas_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped
    If Source=aznar Then

            Return False
    Else 

        Return True

           
        End If

End Sub
Sub barcenas_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
   
End Sub
Sub barcenas_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = barcenas.Y

    'It is removed from the drag'n'drop sources
    DragAndDrop.RemoveSource(Source)

End Sub
 

Attachments

Informatix

Expert
Licensed User
In SrcDragStop, I see no code replacing the actor to its original position if the drop location is invalid, so there's no surprise here.
In my Drag n Drop example I use a drag actor (e.g. CatDrag for the Cat actor) so I don't need to replace anything (the source actor does not move, it is just made visible/invisible).
 

Johnmcenroy

Active Member
Licensed User
Thank you very much for such a great work. I really wanted this wonderful engine. Now Basic4Android has full support of games. As I saw there is also AndEngine now. Thanks again.
 

fanfalveto

Active Member
Licensed User
Hi again,and sorry.
I call puzzle2 from this
B4X:
If n>1 AND n Mod 5=0  Then
StartActivity(puzzle2)
End If
this is the code of puzzle2
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
Dim ti As Timer
End Sub

Sub Globals
    Dim lGdx As LibGDX
    Dim GL As lgGL
    Dim Stage As lgScn2DStage
    Dim Atlas As lgTextureAtlas
    Dim barcenas, bandera,rey As lgScn2DImage
    Dim aznar, chorizo,urdan As lgScn2DImage
    Dim aznar2, chorizo2,urdan2 As lgScn2DImage
    Dim DragAndDrop As lgScn2DDragAndDrop
    Dim DnDPayload As lgScn2DDragAndDropPayload
    Dim re,bar,esp As Int
    Dim p As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Initializes libGDX
    lGdx.Initialize(False, "LG")
    ti.Initialize("ti",7000)
    ti.Enabled=True
    p.SetScreenOrientation(0)
End Sub

Sub Activity_Resume
    'Informs libGDX of Resume events
    If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    'Informs libGDX of Pause events
    If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub LG_Create
    'Initializes the stage
    Stage.Initialize("")
    'Loads the texture atlas
    Atlas.InitializeWithFile("atlas/chori.pack")
    'Creates the actors
    bandera.Initialize3(Atlas.FindRegion("bandera"), "")
    Stage.AddActor(bandera)
    barcenas.Initialize3(Atlas.FindRegion("barcenas"), "")
    Stage.AddActor(barcenas)
    rey.Initialize3(Atlas.FindRegion("rey"), "")
    Stage.AddActor(rey)
aznar2.Initialize3(Atlas.FindRegion("aznar"), "")
    Stage.AddActor(aznar2)
    aznar2.InitializeWithDrawable(aznar2.Drawable, "")
    chorizo2.Initialize3(Atlas.FindRegion("chorizo"), "")
    Stage.AddActor(chorizo2)
    chorizo2.InitializeWithDrawable(chorizo2.Drawable, "")
    urdan2.Initialize3(Atlas.FindRegion("urdan"), "")
    Stage.AddActor(chorizo2)
    urdan2.InitializeWithDrawable(urdan2.Drawable, "")
    aznar.Initialize3(Atlas.FindRegion("aznar"), "")
    Stage.AddActor(aznar)
    aznar.InitializeWithDrawable(aznar.Drawable, "")  
urdan.Initialize3(Atlas.FindRegion("urdan"), "")
    Stage.AddActor(urdan)
    urdan.InitializeWithDrawable(urdan2.Drawable, "")
    chorizo.Initialize3(Atlas.FindRegion("chorizo"), "")
    Stage.AddActor(chorizo)
    chorizo.InitializeWithDrawable(chorizo.Drawable, "")
  'Sets the size and position of actors
    bandera.Height =25%y
    bandera.Width = 25%x
    bandera.X = 0%x
    bandera.Y = 0%y
    barcenas.Height =  25%y
    barcenas.Width =  25%x
    barcenas.X = 0%x
    barcenas.Y =  75%y
    rey.Height =  25%y
    rey.Width =  25%x
    rey.X = 0%x
    rey.Y =  40%y

    aznar.Height =  25%y
    aznar.Width =  25%x
    aznar.X = 75%x
    aznar.Y = 75%y

    chorizo.Height = 25%y
    chorizo.Width = 25%x
    chorizo.X = 75%x
    chorizo.Y =  0%y
  
    urdan.Height =  25%y
    urdan.Width =  25%x
    urdan.X = 75%x
    urdan.Y = 40%y
  
aznar2.Height =  10%y
    aznar2.Width =  10%x
    aznar2.X = 75%x
    aznar2.Y = 75%y

urdan2.Height =  10%y
    urdan2.Width =  10%x
    urdan2.X = 75%x
    urdan2.Y = 40%y

    chorizo2.Height = 10%y
    chorizo2.Width = 10%x
    chorizo2.X = 75%x
    chorizo2.Y =  0%y
  

    'Sets the drag'n'drop sources and targets
    DragAndDrop.Initialize
    DragAndDrop.AddSource(aznar, "aznar")
    DragAndDrop.AddSource(chorizo, "chorizo")
    DragAndDrop.AddSource(urdan, "urdan")
    DragAndDrop.AddTarget(barcenas, "barcenas")
    DragAndDrop.AddTarget(bandera, "bandera")
    DragAndDrop.AddTarget(rey, "rey")

End Sub

Sub LG_Resize(Width As Int, Height As Int)
    'Sets the stage viewport
    Stage.SetViewport(Width, Height, True)
End Sub

Sub LG_Render
    'Clears the screen
    GL.glClearColor(0, 0.7, 0, 1) 'Green
    GL.glClear(GL.GL10_COLOR_BUFFER_BIT)

    'Applies the actions to actors
    Stage.Act

    'Draws the actors
    Stage.Draw
End Sub

Sub LG_Pause
End Sub

Sub LG_Resume
End Sub

Sub LG_Dispose
    'Disposes all resources
    Stage.dispose
    Atlas.dispose
End Sub

Sub aznar_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the family actor invisible
    aznar.Visible = False
    'Sets the drag actor for the family
    DnDPayload.DragActor = aznar2
    DragAndDrop.SetDragActorPosition(-aznar2.Width, aznar2.Height)
    Return DnDPayload
End Sub

Sub aznar_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the family actor visible
    aznar.Visible = True
End Sub

Sub chorizo_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the dog actor invisible
    chorizo.Visible = False

    'Sets the drag actor for the dog
    DnDPayload.DragActor = chorizo2
    DragAndDrop.SetDragActorPosition(-chorizo2.Width, chorizo2.Height)
    Return DnDPayload
End Sub

Sub chorizo_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the dog actor visible
    chorizo.Visible = True
End Sub

Sub urdan_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the dog actor invisible
    urdan.Visible = False

    'Sets the drag actor for the dog
    DnDPayload.DragActor = urdan2
    DragAndDrop.SetDragActorPosition(-urdan2.Width, urdan2.Height)
    Return DnDPayload
End Sub

Sub urdan_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the dog actor visible
    urdan.Visible = True
End Sub


Sub bandera_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped
    If Source=chorizo OR Source=urdan Then

        Return    False
    Else
esp=1
        Return True

          
        End If

End Sub
Sub bandera_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
  
End Sub
Sub bandera_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = bandera.Y

    DragAndDrop.RemoveSource(Source)

End Sub

Sub barcenas_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped

    If Source=urdan OR Source=aznar Then

            Return False
    Else
bar=1
        Return True

          
        End If

End Sub
Sub barcenas_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
  
End Sub
Sub barcenas_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = barcenas.Y

    'It is removed from the drag'n'drop sources
    DragAndDrop.RemoveSource(Source)

End Sub

Sub rey_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped

    If Source=chorizo OR Source=aznar Then

            Return False
    Else
re=1
        Return True

          
        End If

End Sub
Sub rey_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
  
End Sub
Sub rey_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = urdan.Y

    'It is removed from the drag'n'drop sources
    DragAndDrop.RemoveSource(Source)

End Sub
Sub ti_Tick
    control
End Sub
Sub control

ti.Enabled=False
If esp=1 AND re=1 AND bar=1 Then
juego.n=juego.n+10

lGdx.Exit
Activity.Finish
Else
juego.n=juego.n-10
lGdx.Exit
Activity.Finish
End If
End Sub
then when continue in Main crah an this is the log error
B4X:
resumed
juego_lg_render (java line: 1053)
java.lang.NullPointerException


    at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:673)
    at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:633)
    at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SpriteBatch.java:1057)
    at com.badlogic.gdx.graphics.g2d.SpriteBatch.setBlendFunction(SpriteBatch.java:1086)
    at com.badlogic.gdx.graphics.g2d.ParticleEmitter.draw(ParticleEmitter.java:273)
    at com.badlogic.gdx.graphics.g2d.ParticleEffect.draw(ParticleEffect.java:76)
    at anywheresoftware.b4a.libgdx.particles.lgParticleEffect.Draw2(lgParticleEffect.java:64)
    at flm.b4a.lgdxtest.juego._lg_render(juego.java:1053)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.libgdx.LibGDX$LibGDX_Listener.render(LibGDX.java:122)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:497)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1364)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1119)
java.lang.NullPointerException
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()


    at android.os.Handler.<init>(Handler.java:121)
    at android.app.Dialog.<init>(Dialog.java:101)
    at android.app.AlertDialog.<init>(AlertDialog.java:63)
    at android.app.AlertDialog$Builder.create(AlertDialog.java:797)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.libgdx.LibGDX$LibGDX_Listener.render(LibGDX.java:122)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:497)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1364)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1119)
** Activity (juego) Pause, UserClosed = true **
 

Informatix

Expert
Licensed User
The r
Hi again,and sorry.
I call puzzle2 from this
B4X:
If n>1 AND n Mod 5=0  Then
StartActivity(puzzle2)
End If
this is the code of puzzle2
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
Dim ti As Timer
End Sub

Sub Globals
    Dim lGdx As LibGDX
    Dim GL As lgGL
    Dim Stage As lgScn2DStage
    Dim Atlas As lgTextureAtlas
    Dim barcenas, bandera,rey As lgScn2DImage
    Dim aznar, chorizo,urdan As lgScn2DImage
    Dim aznar2, chorizo2,urdan2 As lgScn2DImage
    Dim DragAndDrop As lgScn2DDragAndDrop
    Dim DnDPayload As lgScn2DDragAndDropPayload
    Dim re,bar,esp As Int
    Dim p As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Initializes libGDX
    lGdx.Initialize(False, "LG")
    ti.Initialize("ti",7000)
    ti.Enabled=True
    p.SetScreenOrientation(0)
End Sub

Sub Activity_Resume
    'Informs libGDX of Resume events
    If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    'Informs libGDX of Pause events
    If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub LG_Create
    'Initializes the stage
    Stage.Initialize("")
    'Loads the texture atlas
    Atlas.InitializeWithFile("atlas/chori.pack")
    'Creates the actors
    bandera.Initialize3(Atlas.FindRegion("bandera"), "")
    Stage.AddActor(bandera)
    barcenas.Initialize3(Atlas.FindRegion("barcenas"), "")
    Stage.AddActor(barcenas)
    rey.Initialize3(Atlas.FindRegion("rey"), "")
    Stage.AddActor(rey)
aznar2.Initialize3(Atlas.FindRegion("aznar"), "")
    Stage.AddActor(aznar2)
    aznar2.InitializeWithDrawable(aznar2.Drawable, "")
    chorizo2.Initialize3(Atlas.FindRegion("chorizo"), "")
    Stage.AddActor(chorizo2)
    chorizo2.InitializeWithDrawable(chorizo2.Drawable, "")
    urdan2.Initialize3(Atlas.FindRegion("urdan"), "")
    Stage.AddActor(chorizo2)
    urdan2.InitializeWithDrawable(urdan2.Drawable, "")
    aznar.Initialize3(Atlas.FindRegion("aznar"), "")
    Stage.AddActor(aznar)
    aznar.InitializeWithDrawable(aznar.Drawable, "") 
urdan.Initialize3(Atlas.FindRegion("urdan"), "")
    Stage.AddActor(urdan)
    urdan.InitializeWithDrawable(urdan2.Drawable, "")
    chorizo.Initialize3(Atlas.FindRegion("chorizo"), "")
    Stage.AddActor(chorizo)
    chorizo.InitializeWithDrawable(chorizo.Drawable, "")
  'Sets the size and position of actors
    bandera.Height =25%y
    bandera.Width = 25%x
    bandera.X = 0%x
    bandera.Y = 0%y
    barcenas.Height =  25%y
    barcenas.Width =  25%x
    barcenas.X = 0%x
    barcenas.Y =  75%y
    rey.Height =  25%y
    rey.Width =  25%x
    rey.X = 0%x
    rey.Y =  40%y

    aznar.Height =  25%y
    aznar.Width =  25%x
    aznar.X = 75%x
    aznar.Y = 75%y

    chorizo.Height = 25%y
    chorizo.Width = 25%x
    chorizo.X = 75%x
    chorizo.Y =  0%y
 
    urdan.Height =  25%y
    urdan.Width =  25%x
    urdan.X = 75%x
    urdan.Y = 40%y
 
aznar2.Height =  10%y
    aznar2.Width =  10%x
    aznar2.X = 75%x
    aznar2.Y = 75%y

urdan2.Height =  10%y
    urdan2.Width =  10%x
    urdan2.X = 75%x
    urdan2.Y = 40%y

    chorizo2.Height = 10%y
    chorizo2.Width = 10%x
    chorizo2.X = 75%x
    chorizo2.Y =  0%y
 

    'Sets the drag'n'drop sources and targets
    DragAndDrop.Initialize
    DragAndDrop.AddSource(aznar, "aznar")
    DragAndDrop.AddSource(chorizo, "chorizo")
    DragAndDrop.AddSource(urdan, "urdan")
    DragAndDrop.AddTarget(barcenas, "barcenas")
    DragAndDrop.AddTarget(bandera, "bandera")
    DragAndDrop.AddTarget(rey, "rey")

End Sub

Sub LG_Resize(Width As Int, Height As Int)
    'Sets the stage viewport
    Stage.SetViewport(Width, Height, True)
End Sub

Sub LG_Render
    'Clears the screen
    GL.glClearColor(0, 0.7, 0, 1) 'Green
    GL.glClear(GL.GL10_COLOR_BUFFER_BIT)

    'Applies the actions to actors
    Stage.Act

    'Draws the actors
    Stage.Draw
End Sub

Sub LG_Pause
End Sub

Sub LG_Resume
End Sub

Sub LG_Dispose
    'Disposes all resources
    Stage.dispose
    Atlas.dispose
End Sub

Sub aznar_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the family actor invisible
    aznar.Visible = False
    'Sets the drag actor for the family
    DnDPayload.DragActor = aznar2
    DragAndDrop.SetDragActorPosition(-aznar2.Width, aznar2.Height)
    Return DnDPayload
End Sub

Sub aznar_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the family actor visible
    aznar.Visible = True
End Sub

Sub chorizo_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the dog actor invisible
    chorizo.Visible = False

    'Sets the drag actor for the dog
    DnDPayload.DragActor = chorizo2
    DragAndDrop.SetDragActorPosition(-chorizo2.Width, chorizo2.Height)
    Return DnDPayload
End Sub

Sub chorizo_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the dog actor visible
    chorizo.Visible = True
End Sub

Sub urdan_SrcDragStart(Event As lgScn2DInputEvent, X As Float, Y As Float, Pointer As Int) As lgScn2DDragAndDropPayload
    'Makes the dog actor invisible
    urdan.Visible = False

    'Sets the drag actor for the dog
    DnDPayload.DragActor = urdan2
    DragAndDrop.SetDragActorPosition(-urdan2.Width, urdan2.Height)
    Return DnDPayload
End Sub

Sub urdan_SrcDragStop(Event As lgScn2DInputEvent, DropTarget As lgScn2DActor, X As Float, Y As Float, Pointer As Int)
    'Makes the dog actor visible
    urdan.Visible = True
End Sub


Sub bandera_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped
    If Source=chorizo OR Source=urdan Then

        Return    False
    Else
esp=1
        Return True

         
        End If

End Sub
Sub bandera_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
 
End Sub
Sub bandera_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = bandera.Y

    DragAndDrop.RemoveSource(Source)

End Sub

Sub barcenas_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped

    If Source=urdan OR Source=aznar Then

            Return False
    Else
bar=1
        Return True

         
        End If

End Sub
Sub barcenas_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
 
End Sub
Sub barcenas_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = barcenas.Y

    'It is removed from the drag'n'drop sources
    DragAndDrop.RemoveSource(Source)

End Sub

Sub rey_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
    'Checks whether the source can be dropped

    If Source=chorizo OR Source=aznar Then

            Return False
    Else
re=1
        Return True

         
        End If

End Sub
Sub rey_TgtReset(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload)
 
End Sub
Sub rey_TgtDrop(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int)
    'The source actor is displayed in front of the house
Source.setScale(0.5, 0.5)
    Source.X = Payload.DragActor.X
    Source.Y = urdan.Y

    'It is removed from the drag'n'drop sources
    DragAndDrop.RemoveSource(Source)

End Sub
Sub ti_Tick
    control
End Sub
Sub control

ti.Enabled=False
If esp=1 AND re=1 AND bar=1 Then
juego.n=juego.n+10

lGdx.Exit
Activity.Finish
Else
juego.n=juego.n-10
lGdx.Exit
Activity.Finish
End If
End Sub
then when continue in Main crah an this is the log error
B4X:
resumed
juego_lg_render (java line: 1053)
java.lang.NullPointerException


    at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:673)
    at com.badlogic.gdx.graphics.Mesh.render(Mesh.java:633)
    at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SpriteBatch.java:1057)
    at com.badlogic.gdx.graphics.g2d.SpriteBatch.setBlendFunction(SpriteBatch.java:1086)
    at com.badlogic.gdx.graphics.g2d.ParticleEmitter.draw(ParticleEmitter.java:273)
    at com.badlogic.gdx.graphics.g2d.ParticleEffect.draw(ParticleEffect.java:76)
    at anywheresoftware.b4a.libgdx.particles.lgParticleEffect.Draw2(lgParticleEffect.java:64)
    at flm.b4a.lgdxtest.juego._lg_render(juego.java:1053)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.libgdx.LibGDX$LibGDX_Listener.render(LibGDX.java:122)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:497)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1364)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1119)
java.lang.NullPointerException
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()


    at android.os.Handler.<init>(Handler.java:121)
    at android.app.Dialog.<init>(Dialog.java:101)
    at android.app.AlertDialog.<init>(AlertDialog.java:63)
    at android.app.AlertDialog$Builder.create(AlertDialog.java:797)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.libgdx.LibGDX$LibGDX_Listener.render(LibGDX.java:122)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:497)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1364)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1119)
** Activity (juego) Pause, UserClosed = true **
The error log doesn't match with the provided code. The log reports a problem with a particle effect.
 

fanfalveto

Active Member
Licensed User
Yes i know that,but why? only is when i return of this activity not of other activities. There are 3 activities and only from puzzle2 the program crash in that point
 

Informatix

Expert
Licensed User
Yes i know that,but why? only is when i return of this activity not of other activities. There are 3 activities and only from puzzle2 the program crash in that point
Without the code of other activities, I cannot say anything about your error. It is not related to the code that you sent.
 
Top