Bootstrap输入滑块 - 非常基本的设置

时间:2017-10-23 23:21:32

标签: javascript bootstrap-4 bootstrap-slider

我正在为一个bootstrap' ish输入滑块尝试一个非常基本的设置,不知何故我无法让它工作。

我想要的是什么:

enter image description here

我得到了什么:

enter image description here

来源/工作示例/教程:

http://seiyria.com/bootstrap-slider/

我的代码/来源/错误:

import java.awt.Color;
import java.awt.Shape;
import java.awt.geom.Area;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {

    private List<EZImage> brains = new ArrayList<>(25);

    private Zombie me;

    public static void main(String[] args) throws java.io.IOException {
        new Test();
    }

    public Test() {

        int w = 10;
        int h = 10;

        //create backdrop
        EZ.initialize(w * 33, h * 32);
        EZ.setBackgroundColor(new Color(0, 0, 0));
        me = new Zombie("Zombie.png", 0, 0);

        brains.add(EZ.addImage("Brains.png", (w * 33) / 2, (h * 32 / 2)));

        while (true) {
            detectCollision();
            // check if going to collide with wall
            // we want to check this before we actually move
            // otherwise, we get "stuck" in a situation where we can't move
            // if no collision, we can move
            /*if (EZInteraction.isKeyDown('a')) {
                        if (!isCollisingWall(me, -2, 0)) {
                            me.translateBy(-2, 0);
                        }
                    } else if (EZInteraction.isKeyDown('d')) {
                        if (!isCollisingWall(me, 2, 0)) {
                            me.translateBy(2, 0);
                        }
                    } else if (EZInteraction.isKeyDown('w')) {
                        if (!isCollisingWall(me, 0, -2)) {
                            me.translateBy(0, -2);
                        }
                    } else if (EZInteraction.isKeyDown('s')) {
                        if (!isCollisingWall(me, 0, 2)) {
                            me.translateBy(0, 2);
                        }
                    }*/
            me.go();
            EZ.refreshScreen();
        }
    }

    public boolean doesCollide(EZElement element, EZElement with) {
        Area a = new Area(element.getBounds());
        Area b = new Area(with.getBounds());
        a.intersect(b);
        return !a.isEmpty();
    }

    public void detectCollision() {
        Iterator<EZImage> obstacles = brains.iterator();
        while (obstacles.hasNext()) {
            EZElement next = obstacles.next();
            if (doesCollide(me.zombieSheet, next)) {
                System.out.println("Me = " + me.getBounds().getBounds());
                System.out.println("next = " + next.getBounds().getBounds());
                EZ.removeEZElement(next);
                obstacles.remove();
            }
        }
    }

    public class Zombie {

        EZImage zombieSheet;

        int x = 0;              // Position of Sprite
        int y = 0;

        Zombie(String imgFile, int startX, int startY) {
            x = startX;                 // position of the sprite character on the screen
            y = startY;
            zombieSheet = EZ.addImage(imgFile, x, y);
            setImagePosition();
        }

        public Shape getBounds() {
            return zombieSheet.getBounds();
        }

        private void setImagePosition() {

            // Move the entire sprite sheet
            zombieSheet.translateTo(x, y);
        }

        public void moveDown(int stepSize) {
            y = y + stepSize;
            setImagePosition();
        }

        public void moveLeft(int stepSize) {
            x = x - stepSize;
            setImagePosition();
        }

        public void moveRight(int stepSize) {
            x = x + stepSize;
            setImagePosition();
        }

        public void moveUp(int stepSize) {
            y = y - stepSize;
            setImagePosition();
        }

        // Keyboard controls for moving the character.
        public void go() {
            if (EZInteraction.isKeyDown('w')) {
                moveUp(2);
            } else if (EZInteraction.isKeyDown('a')) {
                moveLeft(2);
            } else if (EZInteraction.isKeyDown('s')) {
                moveDown(2);
            } else if (EZInteraction.isKeyDown('d')) {
                moveRight(2);
            }
        }

    }

}

注意:

我从Web存储库中提取所有基本组件(CSS / JS):bootstrap,bootstrap-slider和JQuery。

1 个答案:

答案 0 :(得分:1)

我在这里为你修好了。 https://jsfiddle.net/k5k9aa70/

您的脚本无序执行,slider未被识别为函数。