当前位置: 首页>>代码示例>>Java>>正文


Java Array.sort方法代码示例

本文整理汇总了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
    }
 
开发者ID:mingwuyun,项目名称:cocos2d-java,代码行数:37,代码来源:EventDispatcher.java

示例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
    }
 
开发者ID:mingwuyun,项目名称:cocos2d-java,代码行数:41,代码来源:EventDispatcher.java

示例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;
}
 
开发者ID:chrisj42,项目名称:miniventure,代码行数:11,代码来源:Tile.java

示例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));
}
 
开发者ID:chrisj42,项目名称:miniventure,代码行数:16,代码来源:WorldObject.java

示例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;
    }
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:68,代码来源:GpgsClient.java

示例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;
}
 
开发者ID:tgobbens,项目名称:fluffybalance,代码行数:21,代码来源:Balanceball.java


注:本文中的com.badlogic.gdx.utils.Array.sort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。