zoukankan      html  css  js  c++  java
  • MarteEngine:Tweens

    如果你已经完成了Animate sprite教程,那么现在是时候看看Tweens了。

    Tweens
    作为一个游戏开发者,一个最普通的事情是移动某个东西。通常是通过改变Entity的坐标实现的,但是有时你有不同的需求,想象一下玩家按照不同的规则改变速度。
    MarteEngine为开发者提供了几个类(和扩展这种机制的能力)来改变Entity的位置的能力:所有这些都集成到Entity本身。
    An Example
    运行这个例子,只创建World,并加入下面这个EntityWithTween:

    public class EntityWithTween extends Entity {

        private Tweener tweener;

        public EntityWithTween(float x, float y) {
            super(x, y);
            setGraphic(ResourceManager.getImage("image"));
                    // add to this entity a tweener
            tweener = new Tweener();
            // add a new Tween to tweener
            tweener.add(new Tween(new LinearMotion(x, y, 400,
                    400, 100, Ease.BOUNCE_IN), true));
                    // start tweens into tweener
            tweener.start();        
        }

        @Override
        public void update(GameContainer container, int delta)
                throws SlickException {
            super.update(container, delta);

            // update player position according to tween
            setPosition(tweener.apply(this));
        }
    }

     上面这些代码是不是很熟悉?新的东西有:

    Tweener类:不要慌!它只是所有Tween的容器。是的,你可以选择将不同的Tween加入到你的Entity中,然后Tweener负责按顺序处理它们。

    Tween类:in this example we declare a basic type of with linear motion from current position of entity (x,y) to (400,400) using an ease function,在这种情况下,BOUNCE_IN. Easing方法提供模拟一个弹跳实体的计算。

    自己动手试一下代码,很简单,很有趣!

     

    ——————————————————————————————————
    傲轩游戏网
  • 相关阅读:
    mvc+struct1+struct2
    JSP中动态include与静态include的区别
    村上春树的经典语录合集
    50. 数组剔除元素后的乘积
    46. 主元素
    Centos7:yum安装MySQL5.7后如何设置root密码
    产品经理人的持续交付和DevOps实践
    利用jenkins实现自动构建、部署,提升团队开发效率
    基于lua-nginx-module(openresty)的WEB应用防火墙
    Nginx+Lua+MySQL/Redis实现高性能动态网页展现
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2378355.html
Copyright © 2011-2022 走看看