Games Help needed, Err: _x2internaltilelayer cannot be cast to _x2objectslayer

fredo

Well-Known Member
Licensed User
Longtime User
While working on @Gunther 's Starting-List I'm stuck at Listpoint 13:
2019-06-28_18-13-33.png

The error occurs when initializing x2tilemap (the Tilemap example was used as a basis).

x2tilemap._prepareobjectsdef (java line: 1305)
java.lang.ClassCastException: b4j.gametest.sn.x2tilemap$_x2internaltilelayer cannot be cast to b4j.gametest.sn.x2tilemap$_x2objectslayer
at b4j.gametest.sn.x2tilemap._prepareobjectsdef(x2tilemap.java:1305)
at b4j.gametest.sn.game._initialize(game.java:171)
at b4j.gametest.sn.main$ResumableSub_AppStart.resume(main.java:80)
at b4j.gametest.sn.main._appstart(main.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.gametest.sn.main.start(main.java:37)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)

2019-06-28_17-31-15.png


The goal is to create a turn-based game using a tile map.

Since this is the first attempt in game development, the mistake will probably be due to a lack of knowledge in the handling of the X2 Game Engine.

Despite the many examples and instructional videos, it has not yet been possible to adequately capture the interaction of the modules involved.

The error occurs in the "X2.b4xlib" as well as in the classes used here. The classes are used to better understand the processes under the bonnet.

A test project is included, so advanced experts may have a better idea of how to apply a help term.
 

Attachments

  • Gametest1.zip
    399.3 KB · Views: 287

Erel

B4X founder
Staff member
Licensed User
Longtime User
LayerTiles1 is a tiles layer.
TileMap.PrepareObjectsDef should only be called with objects layers.

Relevant code from Mario example that handles the tiles layer:
B4X:
Public Sub Tick (GS As X2GameStep)
   mMario.Tick(GS) 'run first as mario updates the world position
   TileMap.DrawScreen(Array("Tile Layer 1", "Tile Layer 2"), GS.DrawingTasks) '<-----
End Sub

Public Sub DrawingComplete
   TileMap.DrawingComplete
End Sub
 
Top