What is the correct way to use this class for hit detection? is it only for debugging or can it actually be used for hit detection in-game?
I am getting GC every few seconds with an average pause of 25 ms. This is causing the screen to stutter. I am assuming updatebounds() should be called every time before checking if two skeletons intersect right? Ive tested it out without updating one over the other and every other combination and it doesn't work without updating, the interest detection of two skeletons.
The method thats causing GC is updateBounds() and digging deeper its these two methods that are allocating memory in the FloatArray class.
int sizeNeededE;
/** Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many
* items to avoid multiple backing array resizes.
* @return {@link #items} */
public float[] ensureCapacity (int additionalCapacity) {
sizeNeededE = size + additionalCapacity;
if (sizeNeededE > items.length) resize(Math.max(8, sizeNeededE));
return items;
}
float[] newItems1;
float[] items1;
protected float[] resize (int newSize) {
newItems1 = new float[newSize];
//newItems1 = null;
items1 = this.items;
System.arraycopy(items1, 0, newItems1, 0, Math.min(size, newSize));
this.items = newItems1;
return newItems1;
}
I have changed them a bit from float[] newItems1 = new float[newSize]; to what you see up there, but I still can't get away from the fact that its still creating a new float and assigning it to the newItems1.
So apart from changing Libgdx's api's is there a possibility that I am using SkeletonBounds wrong (hopefully yes) and if so is there a tutorial or a chart you guys can point me too?
My code
/**
*
* @return the bounds of this animated sprite
*/
public SkeletonBounds getBounds(){
this.bounds.update(spriteSkeleton, true);
return bounds;
}
/**
* do these bounds intersect with the bounds being given?
* @param b bounds being given
* @return returns true if they intersects
*/
public boolean intersectsBounds(SkeletonBounds b){
this.bounds.update(spriteSkeleton, true);
return bounds.aabbIntersectsSkeleton(b);
}
I update the bounds every time i check for an intersection and every time I get the bounds, and only check for intersections when the sprites are a short distance away from each other. so
intersectsBounds(sprite.getBounds);