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


Java ActionListener类代码示例

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


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

示例1: initInput

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
private void initInput(){
    getInputManager().addMapping("LEFT", new KeyTrigger(KeyInput.KEY_J));
    getInputManager().addMapping("RIGHT", new KeyTrigger(KeyInput.KEY_L));
    getInputManager().addMapping("UP", new KeyTrigger(KeyInput.KEY_I));
    getInputManager().addMapping("DOWN", new KeyTrigger(KeyInput.KEY_K));
    getInputManager().addMapping("JUMP", new KeyTrigger(KeyInput.KEY_SPACE));
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        Vector2f movement = new Vector2f();
        if(isPressed){
            switch (name) {
                case "LEFT": movement.setX(-1); break;
                case "RIGHT": movement.setX(+1); break;
                case "UP": movement.setY(-1); break;
                case "DOWN": movement.setY(+1); break;
            }
        }
        entityData.setComponent(character,  new PhysicsCharacterMovement(movement));
    }, "LEFT", "RIGHT", "UP", "DOWN");
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) ->
            entityData.setComponent(character, new PhysicsCharacterState(isPressed, false)
    ), "JUMP");
}
 
开发者ID:jvpichowski,项目名称:ZayES-Bullet,代码行数:23,代码来源:DynamicCharacterExample.java

示例2: initInput

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
private void initInput(){
    getInputManager().addMapping("LEFT", new KeyTrigger(KeyInput.KEY_J));
    getInputManager().addMapping("RIGHT", new KeyTrigger(KeyInput.KEY_L));
    getInputManager().addMapping("UP", new KeyTrigger(KeyInput.KEY_I));
    getInputManager().addMapping("DOWN", new KeyTrigger(KeyInput.KEY_K));
    getInputManager().addMapping("JUMP", new KeyTrigger(KeyInput.KEY_SPACE));
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        Vector2f movement = new Vector2f();
        if(isPressed){
            switch (name) {
                case "LEFT": movement.setX(-1); break;
                case "RIGHT": movement.setX(+1); break;
                case "UP": movement.setY(-1); break;
                case "DOWN": movement.setY(+1); break;
            }
            movement.multLocal(CHARACTER_MASS*MOVE_ACCELERATION);
        }
        entityData.setComponent(character,  new MoveForce(movement));
    }, "LEFT", "RIGHT", "UP", "DOWN");
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        if(isPressed) entityData.setComponent(character, new JumpState(true));
    }, "JUMP");
}
 
开发者ID:jvpichowski,项目名称:ZayES-Bullet,代码行数:24,代码来源:CustomCharacterExample.java

示例3: initInputs

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
private void initInputs() {
    inputManager.addMapping("togglePause", new KeyTrigger(keyInput.KEY_RETURN));
    ActionListener acl = new ActionListener() {
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("togglePause") && keyPressed) {
                if (cinematic.getPlayState() == PlayState.Playing) {
                    cinematic.pause();
                } else {
                    cinematic.play();
                }
            }

        }
    };
    inputManager.addListener(acl, "togglePause");
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:TestCinematic.java

示例4: initInputs

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
private void initInputs() {
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
 
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if(active){
                    active=false;
                    viewPort.removeProcessor(fpp);
                }else{
                    active=true;
                    viewPort.addProcessor(fpp);
                }
            }
        }
    };
         
    inputManager.addListener(acl, "toggle");

}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:TestPosterization.java

示例5: invokeActions

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
private void invokeActions(int hash, boolean pressed) {
    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
        return;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
        Mapping mapping = maps.get(i);
        ArrayList<InputListener> listeners = mapping.listeners;
        int listenerSize = listeners.size();
        for (int j = listenerSize - 1; j >= 0; j--) {
            InputListener listener = listeners.get(j);
            if (listener instanceof ActionListener) {
                ((ActionListener) listener).onAction(mapping.name, pressed, frameTPF);
            }
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:20,代码来源:InputManager.java

示例6: initControls

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
public void initControls(InputManager inputManager) {
    inputManager.deleteMapping(SimpleApplication.INPUT_MAPPING_EXIT);

    inputManager.addMapping("open_menu", new KeyTrigger(KeyInput.KEY_ESCAPE));
    inputManager.addMapping("view_atom", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(new ActionListener() {
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("open_menu".equals(name) && isPressed) {
                NiftyAppState s = stateManager.getState(NiftyAppState.class);
                if ("menu".equals(s.nifty.getCurrentScreen().getScreenId())) {
                    s.exitMenu();
                } else {
                    s.openMenu();
                }
            } else if ("view_atom".equals(name) && isPressed) {
                triggerViewAtom();
            }
        }
    }, "open_menu", "view_atom");
}
 
开发者ID:matthewseal,项目名称:MoleculeViewer,代码行数:22,代码来源:MVAppState.java

示例7: simpleInitApp

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
@Override
public void simpleInitApp() {
    emit = new ParticleEmitter("Emitter", Type.Triangle, 300);
    emit.setGravity(0, 0, 0);
    emit.setVelocityVariation(1);
    emit.setLowLife(1);
    emit.setHighLife(1);
    emit.setInitialVelocity(new Vector3f(0, .5f, 0));
    emit.setImagesX(15);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    emit.setMaterial(mat);
    
    rootNode.attachChild(emit);
    
    inputManager.addListener(new ActionListener() {
        
        public void onAction(String name, boolean isPressed, float tpf) {
            if ("setNum".equals(name) && isPressed) {
                emit.setNumParticles(1000);
            }
        }
    }, "setNum");
    
    inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:27,代码来源:TestMovingParticle.java

示例8: simpleInitApp

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
@Override
public void simpleInitApp() {
    EntityId plane = entityData.createEntity();
    entityData.setComponents(plane,
            new Friction(0),
            new RigidBody(false, 0),
            new CustomShape(new PlaneCollisionShape(new Plane(Vector3f.UNIT_Y.clone(), 0))));

    EntityId box = entityData.createEntity();
    entityData.setComponents(box,
            new Friction(0),
            new WarpPosition(new Vector3f(0,1,0), Quaternion.DIRECTION_Z.clone()),
            new RigidBody(false, 10),
            new BoxShape(),
            new WarpVelocity(new Vector3f(1,0,0), new Vector3f()));

    ESBulletState esBulletState = stateManager.getState(ESBulletState.class);
    esBulletState.onInitialize(() -> {
        BulletDebugAppState debugAppState = new BulletDebugAppState(esBulletState.getPhysicsSpace());
        getStateManager().attach(debugAppState);
    });

    getInputManager().addMapping("JUMP", new KeyTrigger(KeyInput.KEY_SPACE));
    getInputManager().addListener((ActionListener) (name, isPressed, tpf) -> {
        if(isPressed){
            entityData.setComponent(box, new Impulse(new Vector3f(0, 20,0), new Vector3f()));
        }
    }, "JUMP");
}
 
开发者ID:jvpichowski,项目名称:ZayES-Bullet,代码行数:30,代码来源:VelocityImpulseTest.java

示例9: setupFlowControls

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
public void setupFlowControls(ActionListener actionListener) {
    inputManager.deleteMapping(SimpleApplication.INPUT_MAPPING_EXIT);
    inputManager.deleteMapping(SimpleApplication.INPUT_MAPPING_HIDE_STATS);
    inputManager.addMapping(PAUSE, new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping(CAMERA, new KeyTrigger(KeyInput.KEY_C));
    inputManager.addMapping(RESET, new KeyTrigger(KeyInput.KEY_R));
    inputManager.addListener(actionListener, PAUSE, CAMERA, RESET);
}
 
开发者ID:ZoltanTheHun,项目名称:SkyHussars,代码行数:9,代码来源:ControlsMapper.java

示例10: createBallShooter

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
/**
 * creates the necessary inputlistener and action to shoot balls from teh camera
 * @param app
 * @param rootNode
 * @param space
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(1);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:35,代码来源:PhysicsTestHelper.java

示例11: invokeAnalogsAndActions

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) {
    if (value < axisDeadZone) {
        invokeAnalogs(hash, value, !applyTpf);
        return;
    }

    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
        return;
    }

    boolean valueChanged = !axisValues.containsKey(hash);
    if (applyTpf) {
        value *= frameTPF;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
        Mapping mapping = maps.get(i);
        ArrayList<InputListener> listeners = mapping.listeners;
        int listenerSize = listeners.size();
        for (int j = listenerSize - 1; j >= 0; j--) {
            InputListener listener = listeners.get(j);

            if (listener instanceof ActionListener && valueChanged) {
                ((ActionListener) listener).onAction(mapping.name, true, frameTPF);
            }

            if (listener instanceof AnalogListener) {
                ((AnalogListener) listener).onAnalog(mapping.name, value, frameTPF);
            }

        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:36,代码来源:InputManager.java

示例12: setupInput

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
public void setupInput() {
    inputManager.addMapping("start", new KeyTrigger(KeyInput.KEY_PAUSE));
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if(name.equals("start") && isPressed){
                if(cinematic.getPlayState() != PlayState.Playing){
                    cinematic.play();
                }else{
                    cinematic.pause();
                }
            }
        }
    }, "start");
}
 
开发者ID:xbuf,项目名称:jme3_xbuf,代码行数:16,代码来源:TestJaimeJ3o.java

示例13: setupInput

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
public void setupInput() {
	inputManager.addMapping("start", new KeyTrigger(KeyInput.KEY_PAUSE));
	inputManager.addListener(new ActionListener() {

		public void onAction(String name, boolean isPressed, float tpf) {
			if(name.equals("start") && isPressed){
				if(cinematic.getPlayState() != PlayState.Playing){
					cinematic.play();
				}else{
					cinematic.pause();
				}
			}
		}
	}, "start");
}
 
开发者ID:xbuf,项目名称:jme3_xbuf,代码行数:16,代码来源:TestXbufWithMaterialHook.java

示例14: createBallShooter

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
/**
 * creates the necessary inputlistener and action to shoot balls from teh camera
 * @param app a
 * @param rootNode r 
 * @param space s
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:35,代码来源:PhysicsTestHelper.java

示例15: simpleInitApp

import com.jme3.input.controls.ActionListener; //导入依赖的package包/类
@Override
public void simpleInitApp() {

    context = this;

    flyCam.setMoveSpeed(50);
    inputManager.addMapping("PRINT",
            new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addListener(new ActionListener() {
        public void onAction(String name, boolean isPressed, float tpf) {
            System.err.println(cam.getRotation());
            System.err.println(cam.getLocation());
        }
    }, "PRINT");
    cam.setLocation(new Vector3f(-14.938178f, 38.859467f, -66.52032f));
    cam.setRotation(new Quaternion(0.32675794f, -6.513824E-4f, 1.0827737E-5f, 0.9451078f));
    initCrossHairs(); // a "+" in the middle of the screen to help aiming

    /**
     * create four colored boxes and a floor to shoot at:
     */
    //rootNode.attachChild(makeFloor());
    SealField sealField = new SealField(assetManager, inputManager, cam, 10);

    sealField.setLocalTranslation(-40, 0, -40);

    rootNode.attachChild(sealField);

    rootNode.attachChild(assetManager.loadModel("Scenes/world.j3o"));

}
 
开发者ID:kemonoske,项目名称:ArcaneMining,代码行数:32,代码来源:Main.java


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