Getting userData from BitmapText after collision (possible minor code patch)

I’m setting user data on some BitmapText objs like so:

[java]BitmapFont labelFont = assetManager.loadFont(“Interface/Fonts/Default.fnt”);

BitmapText label= new BitmapText(labelFont);

label.setUserData(“id”, id);[/java]

The issue is that when I call getGeometry on the CollisionResult, it returns the BitmapTextPage Geometry object that was collided with, rather than a BitmapText (which isn’t a Geometry). A cheap workaround is to call getParent().getUserData() on the BitmapTextPage obj when the returned Geometry is a BitmapTextPage.

This works, but I think it’d be better to make the change to jME if possible, because it requires logic like this:

[java]Geometry g = collisionResult.getGeometry();

String id = g.getUserData(“id”);

if (id == null) {

id = g.getParent().getUserData(“id”);


(It’s complicated by the fact that BitmapTextPage’s constructor is package-level scope, so we can’t even do an instanceof check to see whether to call getUserData on the collided geometry, or it’s parent. I think the only option is just to go on faith that a null return value from getUserData() means the Geometry is a BitmapTextPage - not such a good idea. Not sure if this is just an oversight and BitmapTextPage’s constructors should actually be public-- then at least we could use instanceof, although it’s still not an ideal solution.)

If BitmapTextPage overrides getUserData() to get data from it’s parent instead, g.getUserData(“id”) would work regardless of the collided obj type. I haven’t tested this yet but if it doesn’t break anything, adding something like this to BitmapTextPage would make things easier:




public <T> T getUserData(String key) {

if (getParent().userData == null) {

return null;


Savable s = getParent().userData.get(key);

if (s instanceof UserData) {

return (T) ((UserData) s).getValue();

} else {

return (T) s;




I don’t think there’s any way/need to use a BitmapTextPage’s get/setUserData methods, anyway. And I believe BitmapTextPage should always have a parent (only used by BitmapText, and it’s package level scope).

Just thought of cleaner instanceof-based workaround (do a check on the public BitmapText class rather than the package scope BitmapTextPage) that we can use outside of jME (although you still may want to consider an override so this isn’t necessary):


public String getUserData(String dataField, CollisionResult cResult) {

Geometry cGeom = cResult.getGeometry();

if (cGeom.getParent() instanceof BitmapText) {

return cGeom.getParent().getUserData(dataField);

} else {

return cGeom.getUserData(dataField);