本文整理匯總了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");
}
示例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");
}
示例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");
}
示例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");
}
示例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);
}
}
}
}
示例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");
}
示例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));
}
示例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");
}
示例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);
}
示例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");
}
示例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);
}
}
}
}
示例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");
}
示例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");
}
示例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");
}
示例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"));
}