本文整理匯總了Java中com.badlogic.gdx.utils.Array.sort方法的典型用法代碼示例。如果您正苦於以下問題:Java Array.sort方法的具體用法?Java Array.sort怎麽用?Java Array.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.utils.Array
的用法示例。
在下文中一共展示了Array.sort方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sortEventListenersOfSceneGraphPriority
import com.badlogic.gdx.utils.Array; //導入方法依賴的package包/類
/** Sorts the listeners of specified type by scene graph priority */
public void sortEventListenersOfSceneGraphPriority(final String listenerID, INode rootNode) {
EventListenerVector listeners = getListeners(listenerID);
if (listeners == null) {return;}
Array<EventListener> sceneGraphListeners = listeners.getSceneGraphPriorityListeners();
if (sceneGraphListeners == null) {return;}
// Reset priority index
_nodePriorityIndex = 0;
_nodePriorityMap.clear();
visitTarget(rootNode, true);
// After sort: priority < 0, > 0
sceneGraphListeners.sort(new Comparator<EventListener>() {
@Override
public int compare(EventListener l1, EventListener l2) {
int p1 = _nodePriorityMap.get(l1._node);
int p2 = _nodePriorityMap.get(l2._node);
return p1 - p2;
}
});
// std::sort(sceneGraphListeners->begin(), sceneGraphListeners->end(), [this](const EventListener* l1, const EventListener* l2) {
// return _nodePriorityMap[l1->getAssociatedNode()] > _nodePriorityMap[l2->getAssociatedNode()];
// });
// #if DUMP_LISTENER_ITEM_PRIORITY_INFO
// log("-----------------------------------");
// for (auto& l : *sceneGraphListeners)
// {
// log("listener priority: node ([%s]%p), priority (%d)", typeid(*l->_node).name(), l->_node, _nodePriorityMap[l->_node]);
// }
// #endif
}
示例2: sortEventListenersOfFixedPriority
import com.badlogic.gdx.utils.Array; //導入方法依賴的package包/類
/** Sorts the listeners of specified type by fixed priority */
public void sortEventListenersOfFixedPriority(final String listenerID) {
EventListenerVector listeners = getListeners(listenerID);
if (listeners == null) {return;}
Array<EventListener> fixedListeners = listeners.getFixedPriorityListeners();
if (fixedListeners == null) {return;}
fixedListeners.sort(new Comparator<EventListener>() {
@Override
public int compare(EventListener o1, EventListener o2) {
return o2.getFixedPriority() - o1.getFixedPriority();
}
});
// After sort: priority < 0, > 0
// std::sort(fixedListeners->begin(), fixedListeners->end(), [](const EventListener* l1, const EventListener* l2) {
// return l1->getFixedPriority() < l2->getFixedPriority();
// });
// FIXME: Should use binary search
int index = 0;
for (EventListener listener : fixedListeners) {
if (listener.getFixedPriority() >= 0)
break;
++index;
}
listeners.setGt0Index(index);
// #if DUMP_LISTENER_ITEM_PRIORITY_INFO
// log("-----------------------------------");
// for (auto& l : *fixedListeners)
// {
// log("listener priority: node (%p), fixed (%d)", l->_node, l->_fixedPriority);
// }
// #endif
}
示例3: sortByDistance
import com.badlogic.gdx.utils.Array; //導入方法依賴的package包/類
/** @noinspection UnusedReturnValue*/
public static Array<Tile> sortByDistance(Array<Tile> tiles, final Vector2 position) {
tiles.sort((t1, t2) -> {
float t1diff = position.dst(t1.getBounds().getCenter(new Vector2()));
float t2diff = position.dst(t2.getBounds().getCenter(new Vector2()));
return Float.compare(t1diff, t2diff);
});
return tiles;
}
示例4: getClosestTile
import com.badlogic.gdx.utils.Array; //導入方法依賴的package包/類
@Nullable
default Tile getClosestTile(@NotNull Array<Tile> tiles) {
if(tiles.size == 0) return null;
Vector2 center = new Vector2();
getBounds().getCenter(center);
HashMap<Vector2, Tile> tileMap = new HashMap<>();
for(Tile t: tiles)
tileMap.put(new Vector2(t.getCenterX(), t.getCenterY()), t);
Array<Vector2> tileCenters = new Array<>(tileMap.keySet().toArray(new Vector2[tileMap.size()]));
tileCenters.sort((v1, v2) -> (int) (center.dst2(v1) - center.dst2(v2))); // sort, so the first one in the list is the closest one
return tileMap.get(tileCenters.get(0));
}
示例5: fetchLeaderboardSync
import com.badlogic.gdx.utils.Array; //導入方法依賴的package包/類
/**
* Blocking version of
* {@link #fetchLeaderboardEntries(String, int, boolean, IFetchLeaderBoardEntriesResponseListener)}
*
* @param leaderBoardId
* @throws IOException
*/
public Array<ILeaderBoardEntry> fetchLeaderboardSync(String leaderBoardId, int limit, boolean aroundPlayer,
boolean friendsOnly) throws IOException {
// TODO implement limit
if (gpgsLeaderboardIdMapper != null)
leaderBoardId = gpgsLeaderboardIdMapper.mapToGsId(leaderBoardId);
if (leaderBoardId == null)
return null;
Array<ILeaderBoardEntry> result = new Array<ILeaderBoardEntry>();
Leaderboard lb = GApiGateway.games.leaderboards().get(leaderBoardId).execute();
// XXX no longer LB info ...
// result.id = lb.getId();
// result.name = lb.getName();
// result.scores = new Array<LeaderBoard.Score>();
// result.iconUrl = lb.getIconUrl();
LeaderboardScores r;
if (aroundPlayer) {
r = GApiGateway.games.scores().listWindow(leaderBoardId, friendsOnly ? "SOCIAL" : "PUBLIC", "ALL_TIME")
.execute();
} else {
r = GApiGateway.games.scores().list(leaderBoardId, friendsOnly ? "SOCIAL" : "PUBLIC", "ALL_TIME").execute();
}
LeaderboardEntry playerScore = r.getPlayerScore();
// player is null when not having a score yet.
// we add it to the list because non-public profile won't appear in
// the full list.
if (playerScore != null) {
GpgsLeaderBoardEntry ps = mapPlayerScore(r.getPlayerScore());
ps.setCurrentPlayer(true);
result.add(ps);
}
// r.getItems is null when no score has been submitted yet.
if (r.getItems() != null) {
for (LeaderboardEntry score : r.getItems()) {
// when player is public it appear in this list as well, so we filter it.
if (playerScore == null || !score.getPlayer().getPlayerId().equals(playerScore.getPlayer()
.getPlayerId())) {
GpgsLeaderBoardEntry s = mapPlayerScore(score);
s.setCurrentPlayer(false);
result.add(s);
}
}
}
// maybe already sorted but API doesn't say anything about it :
// https://developers.google.com/games/services/web/api/scores/list
// so we sort list depending of score meaning.
final int order = "SMALLER_IS_BETTER".equals(lb.getOrder()) ? 1 : -1;
result.sort(new Comparator<ILeaderBoardEntry>() {
@Override
public int compare(ILeaderBoardEntry o1, ILeaderBoardEntry o2) {
return order * Long.compare(o1.getSortValue(), o2.getSortValue());
}
});
return result;
}
示例6: addHighScore
import com.badlogic.gdx.utils.Array; //導入方法依賴的package包/類
private Array<Integer> addHighScore(int score) {
Array<Integer> scores = fetchHighScores();
scores.add(score);
scores.sort();
scores.reverse();
scores.pop();
Preferences prefs = Gdx.app.getPreferences("preferences");
for (int i = 0; i < scores.size; i++) {
prefs.putInteger("score_" + i, scores.get(i));
}
prefs.flush();
return scores;
}