优胜者卡动画发行

时间:2019-03-01 09:09:26

标签: android devexpress

这是我的纸牌位置和里面的优胜者纸牌动画代码      PlayerView.java

 private void startCardAnimation(int placeCardX, int placeCardY, int sourceX, int sourceY, ImageView placedCard, int cardId) {
    placedCard.setImageDrawable(Card.cardImageNameFromId(mContext, cardId));

    Animation animation = null;
    if (placedCard.getId() == R.id.player_destination_card4)
        animation= AnimationUtils.loadAnimation(mContext,R.anim.from_righttoleft);
    else if (placedCard.getId() == R.id.player_destination_card1)
        animation= AnimationUtils.loadAnimation(mContext,R.anim.from_bottomtotop);
    else if (placedCard.getId() == R.id.player_destination_card2)
        animation= AnimationUtils.loadAnimation(mContext,R.anim.from_lefttoright);
    else if (placedCard.getId() == R.id.player_destination_card3)
        animation= AnimationUtils.loadAnimation(mContext,R.anim.from_toptobottom);
    placedCard.startAnimation(animation);
    deleteCache(mContext);

}
  public void placeCardAnimation(int cardId, ImageView placedCard) {
    player_source_card.setVisibility(INVISIBLE);
    placedCard.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            placedCard.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            int[] locations = new int[2];
            placedCard.getLocationOnScreen(locations);
            placeCardX1 = locations[0];
            placeCardY1 = locations[1];
            startCardAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
        }
    });

    player_source_card.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            player_source_card.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            int[] locations = new int[2];
            player_source_card.getLocationOnScreen(locations);
            sourceCardX1 = locations[0];
            sourceCardY1 = locations[1];
            startCardAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
        }
    });
}
    private void startWinnerAnimation(int placeCardX, int placeCardY, int sourceX, int sourceY, ImageView placedCard, int cardId) {
    placedCard.setImageDrawable(Card.cardImageNameFromId(mContext, cardId));
    TranslateAnimation animation = new TranslateAnimation(sourceX - placeCardX, 0, sourceY - placeCardY, 0);
    animation.setDuration(2000);
    animation.setFillAfter(true);
    animation.setInterpolator(new ReverseInterpolator());
    placedCard.startAnimation(animation);
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            placedCard.clearAnimation();
            placedCard.setVisibility(GONE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
}
  public void WinnerCardAnimation(int cardId, ImageView placedCard) {
    player_source_card.setVisibility(INVISIBLE);
    placedCard.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            placedCard.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            int[] locations = new int[2];
            placedCard.getLocationOnScreen(locations);
            placeCardX1 = locations[0];
            placeCardY1 = locations[1];

            startWinnerAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
        }
    });

    player_source_card.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            player_source_card.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            int[] locations = new int[2];
            player_source_card.getLocationOnScreen(locations);
            sourceCardX1 = locations[0];
            sourceCardY1 = locations[1];

            startWinnerAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
        }
    });
}

在此代码内,我们将一张一张一张地获取当前所有用户数据,并获取当前表的详细信息和用户详细信息 PlayCardTable.java

    private void getCurrentTableStatus() {

    JSONObject jsonObject = new JSONObject();
    if (ConstantData.isInternetAvailable(PlayCardTable.this))
        try {

            jsonObject.put(RequestParams.TABLEID, tableId);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    ApplicationClass app = (ApplicationClass) getApplication();
    app.mSocket.emit(RequestParams.GET_CURRENT_TABLE_STATUS, jsonObject);
    app.mSocket.on(RequestParams.GET_CURRENT_TABLE_STATUS + "Reply" + tableId, args -> {

        try {
            String TableStatus = (String) args[0];
            Log.d("CurrentTableStatus---", "" + TableStatus);
            tablestatusjsonobject = new JSONObject(TableStatus);
            Table tempTableStatus = Table.getParseStatus(tablestatusjsonobject, userId);
            if (tempTableStatus.getTableId() == tableId) {
                TIMERCOUNT = 0;
                tableStatus = tempTableStatus;
                Log.d("CurrentTableStatus---", "" + tableStatus.getTableId());
                runOnUiThread(() -> {
                    if (playerImageViewByPlayerId == null
                            || (playerImageViewByPlayerId.size() != tableStatus.getNoOfPlayers())) {
                        initplayerImageViewByPlayerId();
                    }
                    int joinPlayerWithTable = tableStatus.getPlayers().size();
                    if (tableStatus.getNoOfPlayers() == joinPlayerWithTable) {
                        if (tableStatus.getWinnerUserId() != 0 && tableStatus.getWinnerPoints() != 0) {
                            app.mSocket.off(RequestParams.GET_CURRENT_TABLE_STATUS + "Reply");
                            Log.d("User Id ", "Winner User Id : " + tableStatus.getWinnerUserId());
                            Log.d("Winner Point", "Winner Point: " + tableStatus.getWinnerPoints());
                            loadFragments(new ScoreBoardFragment(), "");
                        } else {
                            ConstantData.progressclose();
                            updatePlayerCard();
                            setUpPlayerData();
                            playturn();
                            if (!(tableStatus.isBidDone())) {
                                bidturn();
                            } else if (tableStatus.getMainSuit() != null && tableStatus.getMainSuit().equalsIgnoreCase("")) {
                                selctSuitAndFriends();
                            } else {
                                oldRoundCards = RoundCard.getOldRoundCardData(this);
                                if (oldRoundCards == null || oldRoundCards.isEmpty()) {
                                    RoundCard.setOldRoundCardData(tableStatus.getRoundCards(), this);
                                    oldRoundCards = RoundCard.getOldRoundCardData(this);
                                }
                                Log.d("ThrowCard---round", "" + tableStatus.getRoundCards().size() + "," + oldRoundCards.size());
                                RoundCard updatedThrownCards = getUpdatedThrownCards(oldRoundCards, tableStatus.getRoundCards());
                                if (updatedThrownCards != null && updatedThrownCards.getUserId() != userId) {
                                    Objects.requireNonNull(playerImageViewByPlayerId.get(updatedThrownCards.getUserId())).placeCardAnimation(updatedThrownCards.getCardId(), placedCardPosition.get(updatedThrownCards.getUserId()));
                                    Log.d("animation card-", updatedThrownCards.getCardId() + "," + updatedThrownCards.getUserId());
                                }
                                RoundCard.setOldRoundCardData(tableStatus.getRoundCards(), this);
                                maxBid();
                                partner();
                                selectPartnerCard();

                                setHukumData();
                                setAlreadyThrownCardOnTable(tableStatus.getRoundCards());
                                setUpClickForOtherPlayer();
                            }
                        }
                    } else {
                        ConstantData.progressclose();
                        ConstantData.Displayprogress(PlayCardTable.this, "Please Wait Players Joining  With This Table");
                    }
                });
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.d("CurrentTableStatus---ex", e.toString());
        }
    });
}

此代码用于 PlayCardTable.java

中的动画
    private void setAlreadyThrownCardOnTable(List<RoundCard> roundCards) {
    try {

        roundState = RoundState.getRoundState(PlayCardTable.this);
        if (roundState != null) {
            if (roundCards.size() == tableStatus.getNoOfPlayers()) {

                if (roundState.getRoundAnimationState().equals(RoundAnimationRunning)) {
                    return;
                } else if (roundState.getRoundAnimationState().equals(RoundInComplete)) {
                    roundState.setRoundAnimationState(RoundComplete);
                    roundState.save(this);
                } else if (roundState.getRoundAnimationState().equals(RoundAnimationComplete)) {
                    roundCards.clear();
                }
            }
        }
        if (roundCards.size() != tableStatus.getNoOfPlayers()) {
            if (roundCards.size() > 0) {
                roundState = new RoundState(roundCards.get(0).getRoundNo(), RoundInComplete);
                roundState.save(this);
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }


    if (roundState != null) {

        if (roundState.getRoundAnimationState().equals(RoundComplete)) {
            new Handler().postDelayed(() -> {
                try {
                    if (!tableStatus.getRoundCards().isEmpty()) {
                        if (tableStatus.getRoundCards().get(0).getRoundGoesTo() != 0) {
                            roundState.setRoundAnimationState(RoundAnimationRunning);
                            roundState.save(this);
                            placedCard4.setRotation(90);
                            placedCard2.setRotation(90);


                            for (int i = 0; i < placedCardPosition.size(); i++) {
                                playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
                                        .WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard1);
                                playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
                                        .WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard2);
                                playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
                                        .WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard3);
                                playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
                                        .WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard4);

                            }

                            new Handler().postDelayed(() -> {
                                roundState.setRoundAnimationState(RoundAnimationComplete);
                                roundState.save(PlayCardTable.this);
                                clearThrownCardOnTable();
                            }, 5000);

                        }
                    }
                } catch (Exception ex) {
                    Log.e("", ex.toString());
                }

                roundCards.clear();

            }, 1000);
        }
    }


    if (roundCards.isEmpty())
        clearThrownCardOnTable();
    else {
        for (int i = 0; i < roundCards.size(); i++) {
            Drawable res = Card.cardImageNameFromId(PlayCardTable.this, roundCards.get(i).getCardId());
            ImageView placedCardAsPerUserId = placedCardPosition.get(roundCards.get(i).getUserId());
            if (placedCardAsPerUserId != null) {
                placedCardAsPerUserId.setVisibility(View.VISIBLE);
                placedCardAsPerUserId.setImageDrawable(res);
            }
        }
    }
}

我正在制作纸牌游戏,因为我在将纸牌放入游戏中时遇到了动画问题。以我为例,有4个玩家一起玩游戏。依次旋转,用户会按照放置卡片的方式进行放置,直到4-5转为止,放置卡片的动画都可以正常工作,但是随着播放更多的回合动画变得挂起,并且在7-8回合后其完全停止工作,并且从最近清除了应用程序之后再次恢复游戏它再次工作正常,在4-5转挂起后又恢复正常,在这里我附上了我的游戏视频,动画挂起和相关代码,请帮助我解决此动画问题。

Please Refer link for ios game animation we need that type of animation in Android

0 个答案:

没有答案