zoukankan      html  css  js  c++  java
  • MarteEngine: Rotate and scale

    Alarms and Tweens是唯一的改变你的entity的行为的方式:你可以改变位置(和许多其他属性),但是MarteEngine帮助你操作你的entity的角度和缩放。


    Rotate
    旋转一个entity仅仅是一个角度上的改变,所以MarteEngine可以旋转与entity关联的图像或动画,我们通过定义一个entity上的alarm实现:

    public class RotateEntity extends Entity {

        private static final String ROTATE_ME = "rotate_me";

        public RotateEntity(float x, float y, Image image) {
            super(x, y, image);

            // we set that image or animation must be rotate with Entity
            setCentered(true);
            // we define and alarm so we can rotate entity every 2 seconds
            setAlarm(ROTATE_ME, 2, falsetrue);
        }

        @Override
        public void alarmTriggered(String name) {
            if (name.equalsIgnoreCase(ROTATE_ME)) {
                // let's rotate a bit
                int angle = this.getAngle();
                angle += 2;
                if (angle >= 360)
                    angle -= 360;
                this.setAngle(angle);
            }
        }

    }
    We can mark on setCentered(true) in entity constructor: you must let know to MarteEngine that image or animation associated to entity rotate with it.. in some cases you simply don't want this behaviour.

    Scale

    Scale entity image or animation is not so different: just change scale properties on Entity:

    public class ScaleEntity extends Entity {

        private static final String SCALE_ME = "scale_me";
        private float scaleDir = -0.1f;

        public ScaleEntity(float x, float y, Image image) {
            super(x, y, image);

            // we define and alarm so we can scale entity every 2 seconds
            setAlarm(SCALE_ME, 2, falsetrue);
        }

        @Override
        public void alarmTriggered(String name) {
            if (name.equalsIgnoreCase(SCALE_ME)) {
                // let's scale entity
                this.scale += scaleDir;
                if (this.scale <= 0.1f || this.scale >= 2.0f){
                    scaleDir *= -1;
                }
            }
        }
    }
    In this example we are scaling entity image from a minimum of 0.1 to 2.0 of his original width and height!

    ——————————————————————————————————
    傲轩游戏网
  • 相关阅读:
    CF 936C Lock Puzzle——构造
    LOJ 2980 「THUSCH 2017」大魔法师——线段树
    LOJ 2979 「THUSCH 2017」换桌——多路增广费用流
    LOJ 2978 「THUSCH 2017」杜老师——bitset+线性基+结论
    LOJ 2997 「THUSCH 2017」巧克力——思路+随机化+斯坦纳树
    LOJ 2557 「CTSC2018」组合数问题 (46分)
    bzoj 3158 千钧一发 —— 最小割
    CF1092 D & E —— 思路+单调栈,树的直径
    bzoj 5120 无限之环 & 洛谷 P4003 —— 费用流(多路增广SPFA)
    bzoj 1070 修车 —— 费用流
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2378626.html
Copyright © 2011-2022 走看看