Sort touch areas [SOLVED]

  ... the case you feel the need for a new feature or want to submit one.

Sort touch areas [SOLVED]

Postby Rev.Tyler » Sat Oct 01, 2011 10:24 pm

Hey,


I use Scene.sortChildren all the time. However, I would love if it could sort the touch areas as well.

EDIT:


Here is a sort of barbaric way of doing it that I rigged up. It's extremely inefficient due to the multiple list casting, but I couldn't think of another way of getting from ITouchArea to IEntity(to use the z-index) and back again.

There are two methods, the boolean parameter gives you the option of sorting the children and the touch areas of a scene.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /**
  2.  * Sorts all the registered touch areas by the {@link IEntity}'s Z index
  3.  *
  4.  * @param sortChildren True to sort children as well as touch areas.
  5.  */
  6. public void sortTouchAreas(boolean sortChildren){
  7.         if(sortChildren){
  8.                 this.sortChildren();
  9.                 sortTouchAreas();
  10.         }else{
  11.                 sortTouchAreas();
  12.         }
  13. }
  14.  
  15. /**
  16.  * Sorts all the registered touch areas by the {@link IEntity}'s Z index
  17.  */
  18. public void sortTouchAreas(){
  19.         if(this.mTouchAreas != null){
  20.                 ArrayList<ITouchArea> touchAreas = new ArrayList<ITouchArea>();
  21.                 IEntity[] touchEntities = ZIndexSorter.getInstance().sort(this.mTouchAreas.toArray(new IEntity[0]));
  22.                 for(int i = 0; i < touchEntities.length; i++){
  23.                         touchAreas.add((ITouchArea)touchEntities[i]);
  24.                 }
  25.                 this.mTouchAreas = null;
  26.                 this.mTouchAreas = new SmartList<Scene.ITouchArea>();
  27.                 this.mTouchAreas.addAll(touchAreas);
  28.         }
  29. }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
Rev.Tyler
 
Posts: 161
Joined: Tue Dec 28, 2010 5:02 am

Re: Sort touch areas [SOLVED]

Postby jar » Thu Dec 19, 2013 7:30 pm

Hi. I get the error in GLES2:

Type mismatch: cannot convert from void to IEntity[]

Was it for GLES1?

In GLES2 here is: SmartList<ITouchArea> mTouchAreas and you cannot convert it to IEntity[].
jar
 
Posts: 52
Joined: Wed Jan 12, 2011 5:22 pm
Location: Poland


Return to Features

Who is online

Users browsing this forum: No registered users and 9 guests