In my dreams I'd quit my job and dedicate full time to game programming, but it's not a realistic scenario
Sub Process_Globals
Private scalex, scaley, vpW, vpH As Float
End Sub
Sub CreateLevel(world As lgBox2DWorld, tiledmap As lgMapTiledMap, scalexfactor As Float, scaleyfactor As Float, LgWidth As Float, LgHeight As Float)
vpW = LgWidth
vpH = LgHeight
scalex = scalexfactor
scaley = scaleyfactor
Dim layerint As Int = -1
For i = 0 To tiledmap.Layers.GetAllLayers.Size-1
Dim layer As lgMapLayer = tiledmap.Layers.GetAllLayers.Get(i)
If layer.Name = "objectlayer1" Then
layerint = i
Exit
End If
Next
If layerint < 0 Then Return
For Each obj As lgMapRectangleMapObject In tiledmap.Layers.Get(layerint).Objects.GetAllObjects
Dim Box As lgBox2DPolygonShape
Box.SetAsBox2((obj.Rectangle.width/2)/scalex,(obj.Rectangle.height/2)/scaley,world2box2d(obj.Rectangle.x,obj.Rectangle.y,obj.Rectangle.width,obj.Rectangle.height),0)
Dim fd As lgBox2DFixtureDef
fd.shape = Box
fd.restitution = 0.2
fd.Density = 1
fd.friction = 1
Dim bd_def As lgBox2DBodyDef
bd_def.type = world.BODYTYPE_Static
bd_def.position.set(0,0)
Dim box2dbody As lgBox2DBody
box2dbody = world.createBody(bd_def)
box2dbody.createFixture(fd)
box2dbody.UserData = obj.Name
Box.dispose
Next
End Sub
private Sub world2box2d (posx As Float, posy As Float, width As Float, height As Float) As lgMathVector2
Dim vector As lgMathVector2
vector.x = ((posx + (width/2)) - (vpW/2)) / scalex
vector.y = ((posy + (height/2)) - (vpH/2) ) / scaley
Return vector
End Sub
Dim tilemap As lgMapTmxMapLoader
tilemap.Initialize
tiledmap = tilemap.Load("test.tmx")
tmr.Initialize(tiledmap)
LoadLevelTiled.CreateLevel(World,tiledmap,scaleX,scaleY,vpW,vpH)
'Code module
Sub Process_Globals
Private scalex, scaley, vpW, vpH As Float
End Sub
Sub CreateLevel(world As lgBox2DWorld, tiledmap As lgMapTiledMap, scalexfactor As Float, scaleyfactor As Float, LgWidth As Float, LgHeight As Float)
vpW = LgWidth
vpH = LgHeight
scalex = scalexfactor
scaley = scaleyfactor
Dim layerint As Int = -1
For i = 0 To tiledmap.Layers.GetAllLayers.Size-1
Dim layer As lgMapLayer = tiledmap.Layers.GetAllLayers.Get(i)
If layer.Name = "objectlayer1" Then
layerint = i
Exit
End If
Next
If layerint < 0 Then Return
For Each obj As lgMapObject In tiledmap.Layers.Get(layerint).Objects.GetAllObjects
If obj Is lgMapPolygonMapObject Then
Dim polygonobj As lgMapPolygonMapObject = obj
Dim polygon As lgBox2DPolygonShape
Dim newVertices(polygonobj.Polygon.Vertices.Length) As Float
For i = 0 To polygonobj.Polygon.Vertices.Length - 1
Dim ver As Float = polygonobj.Polygon.Vertices(i)
newVertices(i) = ver / scalex
Next
polygon.Set2(newVertices)
Dim polygonShapeDef As lgBox2DFixtureDef
polygonShapeDef.shape = polygon
polygonShapeDef.restitution=0.2
polygonShapeDef.Density = 0.5
Dim polygonBodyDef As lgBox2DBodyDef
polygonBodyDef.Type = world.BODYTYPE_Static
polygonBodyDef.position.set(world2box2d(polygonobj.Polygon.X,polygonobj.Polygon.Y,0,0).x,world2box2d(polygonobj.Polygon.X,polygonobj.Polygon.Y,0,0).y)
Dim polygonbody As lgBox2DBody
polygonbody = world.createBody(polygonBodyDef)
polygonbody.createFixture(polygonShapeDef)
polygonbody.UserData = polygonobj.Name
polygon.dispose
Log("polygon created")
else if obj Is lgMapRectangleMapObject Then
Dim rectobj As lgMapRectangleMapObject = obj
Dim Box As lgBox2DPolygonShape
Box.SetAsBox2((rectobj.Rectangle.width/2)/scalex,(rectobj.Rectangle.height/2)/scaley,world2box2d(rectobj.Rectangle.x,rectobj.Rectangle.y,rectobj.Rectangle.width,rectobj.Rectangle.height),0)
Dim fd As lgBox2DFixtureDef
fd.shape = Box
fd.restitution = 0.2
fd.Density = 1
fd.friction = 1
Dim bd_def As lgBox2DBodyDef
bd_def.type = world.BODYTYPE_Static
bd_def.position.set(0,0)
Dim box2dbody As lgBox2DBody
box2dbody = world.createBody(bd_def)
box2dbody.createFixture(fd)
box2dbody.UserData = obj.Name
Box.dispose
Log("box created")
End If
Next
End Sub
private Sub world2box2d (posx As Float, posy As Float, width As Float, height As Float) As lgMathVector2
Dim vector As lgMathVector2
vector.x = ((posx + (width/2)) - (vpW/2)) / scalex
vector.y = ((posy + (height/2)) - (vpH/2) ) / scaley
Return vector
End Sub
For more complex objects you can use the physics body editor tool.
And for other objects (enemies, traps, mechanisms...) i just draw a little rectangle in an object layer and add some custom properties (ie: type of platform, speed, stop time...). And when loading I just read the x and y values and then init the object with the parameters.
I'd like to add also a polyline object, for more complex shapes...
'Code module
Sub Process_Globals
End Sub
Sub CreateLevel(world As lgBox2DWorld, tiledmap As lgMapTiledMap)
Private scalex As Float = Main.scaleX
Private scaley As Float = Main.scaleY
Dim layerint As Int = -1
For i = 0 To tiledmap.Layers.GetAllLayers.Size-1
Dim layer As lgMapLayer = tiledmap.Layers.GetAllLayers.Get(i)
If layer.Name = "objectlayer1" Then
layerint = i
Exit
End If
Next
If layerint < 0 Then Return
For Each obj As lgMapObject In tiledmap.Layers.Get(layerint).Objects.GetAllObjects
If obj Is lgMapPolygonMapObject Then
Dim polygonobj As lgMapPolygonMapObject = obj
Dim polygon As lgBox2DPolygonShape
Dim newVertices(polygonobj.Polygon.Vertices.Length) As Float
For i = 0 To polygonobj.Polygon.Vertices.Length - 1
Dim ver As Float = polygonobj.Polygon.Vertices(i)
newVertices(i) = ver / scalex
Next
polygon.Set2(newVertices)
Dim polygonShapeDef As lgBox2DFixtureDef
polygonShapeDef.shape = polygon
polygonShapeDef.restitution=0.2
polygonShapeDef.Density = 0.5
Dim polygonBodyDef As lgBox2DBodyDef
polygonBodyDef.Type = world.BODYTYPE_Static
polygonBodyDef.position.set(PosCon.world2box2d(polygonobj.Polygon.X,polygonobj.Polygon.Y,0,0).x,PosCon.world2box2d(polygonobj.Polygon.X,polygonobj.Polygon.Y,0,0).y)
Dim polygonbody As lgBox2DBody
polygonbody = world.createBody(polygonBodyDef)
polygonbody.createFixture(polygonShapeDef)
polygonbody.UserData = polygonobj.Name
polygon.dispose
Log("polygon created")
else if obj Is lgMapRectangleMapObject Then
Dim rectobj As lgMapRectangleMapObject = obj
Dim Box As lgBox2DPolygonShape
Box.SetAsBox2((rectobj.Rectangle.width/2)/scalex,(rectobj.Rectangle.height/2)/scaley,PosCon.world2box2d(rectobj.Rectangle.x,rectobj.Rectangle.y,rectobj.Rectangle.width,rectobj.Rectangle.height),0)
Dim fd As lgBox2DFixtureDef
fd.shape = Box
fd.restitution = 0.2
fd.Density = 1
fd.friction = 1
Dim bd_def As lgBox2DBodyDef
bd_def.type = world.BODYTYPE_Static
bd_def.position.set(0,0)
Dim box2dbody As lgBox2DBody
box2dbody = world.createBody(bd_def)
box2dbody.createFixture(fd)
box2dbody.UserData = obj.Name
Box.dispose
Log("box created")
else if obj Is lgMapEllipseMapObject Then
Dim circleobj As lgMapEllipseMapObject = obj
Dim Circle As lgBox2DCircleShape
Circle.Radius = (circleobj.Ellipse.width/scalex)/2
Dim circlefd As lgBox2DFixtureDef
circlefd.shape = Circle
circlefd.density = 1
circlefd.restitution = 0.2
circlefd.friction = 1
circlefd.isSensor = True
Dim circledef As lgBox2DBodyDef
circledef.type = world.BODYTYPE_Static
circledef.position.Set(PosCon.world2box2d(circleobj.Ellipse.x,circleobj.Ellipse.Y,0,0).x+Circle.Radius,PosCon.world2box2d(circleobj.Ellipse.x,circleobj.Ellipse.Y,0,0).y+Circle.Radius)
Dim circlebody As lgBox2DBody
circlebody = world.CreateBody(circledef)
circlebody.createFixture(circlefd)
circlebody.UserData = obj.Name
Circle.dispose
else if obj Is lgMapPolylineMapObject Then
Dim polylineobj As lgMapPolylineMapObject = obj
Dim chain As lgBox2DChainShape
Dim newVertices(polylineobj.Polyline.Vertices.Length) As Float
For i = 0 To polylineobj.Polyline.Vertices.Length - 1
Dim ver As Float = polylineobj.Polyline.Vertices(i)
newVertices(i) = ver / scalex
Next
chain.createChain(newVertices)
Dim chainShapeDef As lgBox2DFixtureDef
chainShapeDef.shape = chain
chainShapeDef.restitution=0.2
chainShapeDef.Density = 0.5
Dim chainBodyDef As lgBox2DBodyDef
chainBodyDef.Type = world.BODYTYPE_Static
chainBodyDef.position.set(PosCon.world2box2d(polylineobj.Polyline.X,polylineobj.Polyline.Y,0,0).x,PosCon.world2box2d(polylineobj.Polyline.X,polylineobj.Polyline.Y,0,0).y)
Dim chainbody As lgBox2DBody
chainbody = world.createBody(chainBodyDef)
chainbody.createFixture(chainShapeDef)
chainbody.UserData = polylineobj.Name
chain.dispose
Log("polyline created")
End If
Next
End Sub
the thing is that the lgInputProcessor or lgGestureDetector cannot recognize a touch and hold event like a simple android panel view.
they can recognize a touch down and touch up but not when i hold the down. i needed that for my moped game where i touch the Gas Pedal and could not figure it out.
i dont want to stop only when touch up was fired i would like to have a touch and hold event.
i also need to investigate the how to make menus and animate them like you did in your games. can i have panels and add views in it and move only that panel around instead of moving each button?
Private Sub FromScreenToWorld(ScreenX As Int, ScreenY As Int) As lgMathVector2
'Translates the screen coordinates into viewport/world coordinates
Dim Coord As lgMathVector2
Coord.set(ScreenX, ScreenY)
cameraGUI.Unproject(Coord)
Return Coord
End Sub
Public Sub touchLeft(x As Float, y As Float) As Boolean
Dim where As lgMathVector2 = FromScreenToWorld(x,y)
Return (where.x < cameraGUI.ViewportWidth/2)
End Sub
Public Sub touchRight(x As Float, y As Float) As Boolean
Dim where As lgMathVector2 = FromScreenToWorld(x,y)
Return (where.x >= cameraGUI.ViewportWidth/2)
End Sub
Sub IP_TouchDown(screenX As Int, screenY As Int, Pointer As Int) As Boolean
If touchLeft(screenX, screenY) Then
leftPointer = Pointer
End If
If touchRight(screenX, screenY) Then
rightPointer = Pointer
End If
End Sub
Sub IP_touchup(screenX As Int, screenY As Int, pointer As Int)
Select Case pointer
Case leftPointer
leftPointer = -1
Case rightPointer
rightPointer = -1
End Select
End Sub
car.handleInputs(leftPointer, rightPointer)
Hello there!
In my games I'm not using scene2D, just textureRegions and sprites. For the GUI I use textureregions and I animate them via interpolators. Maybe a lot of work without using scene2D... but it works!
And for the touch events, this is what I have in my car game, where IP is inputProcessor, and cameraGUI is a camera I have only to show the GUI:
'Class module
Sub Class_Globals
...
Dim interpolator As lgMathInterpolation
Dim finalPosition As lgMathVector2
Dim initialPosition As lgMathVector2
Dim actualPosition As lgMathVector2
Dim duracionAnim As Float
Dim interpolator As lgMathInterpolation
Dim time As Float
Dim texture As lgTextureRegion
...
End Sub
Public Sub draw (batch As lgSpriteBatch, delta As Float)
Dim progress As Float
Dim a As Float
...
time = time + delta
progress = time / duracionAnim
a = interpolator.apply (progress)
If progress >=1 Then
progress = 1
animating = False
inPlace = True
End If
actualPosition.x = initialPosition.x + a * (finalPosition.x - initialPosition.x)
actualPosition.y = initialPosition.y + a * (finalPosition.y - initialPosition.y)
...
'Draw
batch.DrawRegion (texture,actualPosition.x-texture.RegionWidth/2,actualPosition.y-texture.RegionHeight/2)
This as well...In my games I'm not using scene2D, just textureRegions and sprites.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?