AndEngine

andymc

Well-Known Member
Licensed User
Longtime User
It looks good, but we would need someone to write a wrapper for B4A to use it. Would be brilliant if someone could as it's a very capable looking game engine and would make B4A perfect for writing fast smooth 2D games. It includes a physics engine too! And sound!
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
I actually ported a few features of AndEngine a while ago, but i was stuck as I need to start an activity from the engine and i don't know how.

B4X:
public class AndEngineWrapper extends BaseGameActivity {

I already added Scenes, camera and some other stuff. Here's how it looks like in B4A:

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   'Declaration of Variables
   Dim Lives, Hitpoints As Int
   Dim CameraWidth, CameraHeight As Int

   'Declaration of Views
   Dim pnlGame As Panel
   Dim vwRender As RSRenderView
   
   'Declaration of Libraries
   Dim Engine As AndEngine
   Dim Camera As AndCamera
   Dim Scene As AndScene
   Dim Constants As AndConstants

End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   'Load Activity Stuff
   Activity.LoadLayout("Game.bal")
   
   'Initialize variables
   Lives = 3
   Hitpoints = 100
   CameraWidth = pnlGame.Width
   CameraHeight = pnlGame.Height
   
   'Initialize views
   vwRender.Initialize("RenderView")
   
   'Initialize AndEngine
   LoadEngine
   
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

'Loads the AndEngine
Sub LoadEngine
   'First we need a Camera Object
   'A Camera object is needed as a holder of the enginer. See like a panel
   Camera.Initialize("Camera", CameraWidth, CameraHeight)
   
   'Next we will create a scene
   'A scene is the object where we will draw on. See like a canvas
   Scene.Initialize("Scene")
   Scene.setBackgroundColor(123, 231,5)
   
   'Initializes the AndEngine which passes the camera and the screen orientation.
   'The width and height are extracted from the camera.
   Engine.Orientation = Constants.ORIENTATION_LANDSCAPE
   Engine.Initialize("Engine", Camera.Camera, Engine.Orientation)
   
   'Checks to be certain that some variabels are not null. - Debugging.
   Engine.isNull(Engine.Engine)
   Engine.isNull(Camera.Camera)
   Engine.isNull(vwRender)
   
   'Starts the Engine
   Engine.start
   
   'We pass the Scene to the Engine.
   Engine.Scene = Scene.Scene
   
   'We set the RenderView to render the Engine
   vwRender.Renderer = Engine.Engine
   
   'Now let's try to add the Engine to the Panel
   'pnlGame.AddView(vwRender, 0dip, 0dip, 100%x, 100%y)
        '----Here's where i'm currently stuck at. ---------
   StartActivity(Engine.CreateIntent)
   


End Sub


Tomas
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Hi X, i too would love to have this capability in B4A, this will also be able to be used for Live Wallpaper, i have been trying to use the java code in Eclipse, but since i'm no expert in Java, i left it alone, it would awesome if you could finish up this library buddy!

cheers,
Walter
 
Upvote 0
Top