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


Java OutForAnimationCallback类代码示例

本文整理汇总了Java中net.sf.freecol.client.gui.OutForAnimationCallback的典型用法代码示例。如果您正苦于以下问题:Java OutForAnimationCallback类的具体用法?Java OutForAnimationCallback怎么用?Java OutForAnimationCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OutForAnimationCallback类属于net.sf.freecol.client.gui包,在下文中一共展示了OutForAnimationCallback类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: animate

import net.sf.freecol.client.gui.OutForAnimationCallback; //导入依赖的package包/类
/**
 * Do the animation.
 */
public void animate() {
    if (gui.getTilePosition(tile) == null) return;

    // Painting the whole screen once to get rid of disposed dialog-boxes.
    gui.paintImmediatelyCanvasInItsBounds();
    gui.executeWithUnitOutForAnimation(unit, tile, new OutForAnimationCallback() {
        public void executeWithUnitOutForAnimation(final JLabel unitLabel) {
            for (AnimationEvent event : animation) {
                long time = System.nanoTime();
                if (event instanceof ImageAnimationEvent) {
                    final ImageAnimationEvent ievent = (ImageAnimationEvent) event;
                    final ImageIcon icon = (ImageIcon)unitLabel.getIcon();
                    icon.setImage(ievent.getImage());
                    gui.paintImmediatelyCanvasIn(getDirtyAnimationArea());

                    time = ievent.getDurationInMs()
                        - (System.nanoTime() - time) / 1000000;
                    if (time > 0) {
                        try {
                            Thread.sleep(time);
                        } catch (InterruptedException ex) {
                            //ignore
                        }
                    }
                }
            }             
        }
    });
}
 
开发者ID:vishal-mittal,项目名称:SOEN6471-FreeCol,代码行数:33,代码来源:UnitImageAnimation.java

示例2: animate

import net.sf.freecol.client.gui.OutForAnimationCallback; //导入依赖的package包/类
/**
 * Do the animation.
 */
public void animate() {
    final int movementSpeed = gui.getAnimationSpeed(unit);
    final Point srcP = gui.getTilePosition(sourceTile);
    final Point dstP = gui.getTilePosition(destinationTile);
    
    if (srcP == null || dstP == null || movementSpeed <= 0) return;

    float scale = gui.getMapScale();
    final int movementRatio = (int)(Math.pow(2, movementSpeed + 1) * scale);
    final Rectangle r1 = gui.getTileBounds(sourceTile);
    final Rectangle r2 = gui.getTileBounds(destinationTile);
    final Rectangle bounds = r1.union(r2);

    gui.executeWithUnitOutForAnimation(unit, sourceTile,
        new OutForAnimationCallback() {
            public void executeWithUnitOutForAnimation(final JLabel unitLabel) {
                final Point srcPoint
                    = gui.getMapViewer().getUnitLabelPositionInTile(unitLabel, srcP);
                final Point dstPoint
                    = gui.getMapViewer().getUnitLabelPositionInTile(unitLabel, dstP);
                final double xratio = gui.getMapViewer().getTileWidth()
                    / gui.getMapViewer().getTileHeight();
                final int stepX = (srcPoint.getX() == dstPoint.getX()) ? 0
                    : (srcPoint.getX() > dstPoint.getX()) ? -1 : 1;
                final int stepY = (srcPoint.getY() == dstPoint.getY()) ? 0
                    : (srcPoint.getY() > dstPoint.getY()) ? -1 : 1;
                
                // Painting the whole screen once to get rid of
                // disposed dialog-boxes.
                gui.paintImmediatelyCanvasInItsBounds();
                
                int dropFrames = 0;
                Point point = srcPoint;
                while (!point.equals(dstPoint)) {
                    long time = System.currentTimeMillis();
                    
                    point.x += stepX * xratio * movementRatio;
                    point.y += stepY * movementRatio;
                    if ((stepX < 0 && point.x < dstPoint.x)
                        || (stepX > 0 && point.x > dstPoint.x)) {
                        point.x = dstPoint.x;
                    }
                    if ((stepY < 0 && point.y < dstPoint.y)
                        || (stepY > 0 && point.y > dstPoint.y)) {
                        point.y = dstPoint.y;
                    }
                    if (dropFrames <= 0) {
                        unitLabel.setLocation(point);
                        gui.paintImmediatelyCanvasIn(bounds);
                        
                        int timeTaken = (int)(System.currentTimeMillis()
                            - time);
                        final int waitTime = ANIMATION_DELAY - timeTaken;
                        if (waitTime > 0) {
                            try {
                                Thread.sleep(waitTime);
                            } catch (InterruptedException ex) {
                                //ignore
                            }
                            dropFrames = 0;
                        } else {
                            dropFrames = timeTaken / ANIMATION_DELAY - 1;
                        }
                    } else {
                        dropFrames--;
                    }
                }
            }
        });
}
 
开发者ID:vishal-mittal,项目名称:SOEN6471-FreeCol,代码行数:74,代码来源:UnitMoveAnimation.java


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