Hi I’m trying to code a listener for a feature in my game but I keep getting this error for line 188
error: illegal start of expression
public void onAnalog(String name, float intensity, float tpf)
this is odd because I have another listener with the same data type decleration and that works perfectly fine and here is my code
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.math.FastMath;
import com.jme3.system.AppSettings;
import com.jme3.input.*;
import com.jme3.input.controls.*;
import com.jme3.scene.Node;
import com.jme3.math.Ray;
import com.jme3.collision.*;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
* @author normenhansen
*/
public class Main extends SimpleApplication {
//cube generator code
private static Box mesh = new Box(Vector3f.ZERO,1,1,1);
public Geometry myBox(String name, Vector3f loc, ColorRGBA color)
{
Geometry geom3 = new Geometry(name, mesh);
Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat3.setColor("Color", color );
geom3.setMaterial(mat3);
geom.setLocalTranslation(loc);
return geom3;
}
//crosshair/screen marker 2d
private void attachCenterMark()
{
Geometry c = myBox("center mark", Vector3f.ZERO, ColorRGBA.White);
c.scale(4);
c.setLocalTranslation(settings.getWidth()/2, settings.getHeight()/2, 0);
guiNode.attachChild(c);
}
//geometry mesh instance
private Geometry geom2;
private Geometry geom;
//class objects for keys and buttons, trigger mapping
private final static Trigger TRIGGER_COLOR = new KeyTrigger(KeyInput.KEY_SPACE);
private final static Trigger TRIGGER_ROTATE = new MouseButtonTrigger(MouseInput.BUTTON_LEFT);
private final static String MAPPING_COLOR = "Toggle color";
private final static String MAPPING_ROTATE = "Rotate";
public static void main(String[] args) {
//app object
Main app = new Main();
//settings
//app settings object
AppSettings settings = new AppSettings(true);
//resolution settings
settings.setResolution(450, 640);
//splashscreen image
settings.setSettingsDialogImage("Interface/splashscreen.jpg");
//game title
settings.setTitle("Laser Cube");
//apply settings
app.setSettings(settings);
app.start();
}
@Override
public void simpleInitApp() {
//trigger map registration
inputManager.addMapping(MAPPING_COLOR, TRIGGER_COLOR);
inputManager.addMapping(MAPPING_ROTATE, TRIGGER_ROTATE);
inputManager.addListener(actionListener, new String[]{MAPPING_COLOR});
inputManager.addListener(analogListener, new String[]{MAPPING_ROTATE});
//first original box
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
//shrink the blue cube
geom.setLocalScale(0.5f);
//rotate the cube with quaternions
Quaternion roll045 = new Quaternion();
//supply angel and axis as arguments
roll045.fromAngleAxis(45*FastMath.DEG_TO_RAD, Vector3f.UNIT_X);
geom.setLocalRotation(roll045);
//my box
//create vecot object
Vector3f v2 = new Vector3f(2.0f, 1.0f, -3.0f);
//create box object
Box b2 = new Box(Vector3f.ZERO, 1, 1, 1);
//create geometry for box object
geom2 = new Geometry("Box", b2);
//create materal for box object
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
//assign color to material
mat2.setColor("Color", ColorRGBA.Yellow);
//set material to geometry
geom2.setMaterial(mat2);
//set location of cube
geom2.setLocalTranslation(v2);
//attach geometry to root node
rootNode.attachChild(geom2);
//enlarge the yellow cube
geom2.scale(2.0f);
//rotate the cube by degrees to radians
float r = FastMath.DEG_TO_RAD * 45;
geom2.rotate(0.0f, r, 0.0f);
//call the center mark method
attachCenterMark();
//set the node for two cubes of different color by using the generator
rootNode.attachChild(myBox("Red Cube", new Vector3f(0.0f, 2.5f, 0.0f), ColorRGBA.Red));
rootNode.attachChild(myBox("Blue Cube", new Vector3f(0.0f, -2.5f, 0.0f), ColorRGBA.Blue));
}
//listener objects for keys and buttons plus implementation
private ActionListener actionListener = new ActionListener()
{
public void onAction(String name, boolean isPressed, float tpf)
{
System.out.println("You triggered: " + name);
if(name.equals(MAPPING_COLOR) && !isPressed)
{
//implement action here -- change cubes color
geom.getMaterial().setColor("Color", ColorRGBA.randomColor());
}
}
};
private AnalogListener analogListener = new AnalogListener()
{
public void onAnalog(String name, float intensity, float tpf)
{
System.out.println("You triggered: " + name);
if(name.equals(MAPPING_ROTATE))
{
//implement action here -- rotate cube
geom2.rotate(0, intensity, 0);//rotate around y-axis
}
}
};
//analog listener for the crosshair object collisions/selection
private AnalogListener turretFire = new AnalogListener();
{
public void onAnalog(String name, float intensity, float tpf)
if (name.equals(MAPPING_ROTATE))
{
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
rootNode.collideWith(ray, results);
for (int i = 0; i < results.size(); i++)
{
float dist = results.getCollision(i).getDistance();
Vector3f pt = results.getCollision(i).getContactPoint();
String target = results.getCollision(i).getGeometry().getName();
System.out.println("Selection: # " + i + ": " + target + "at " + pt + ", " + dist + "WU away.");
}
if (results.size() > 0)
{
Geometry target = results.getClosestCollision().getGeometry();
//implementation
if(target.getName().equals("Red Cube"))
{
target.rotate(0, -intensity, 0)//rotate left
}else if (target.getName().equals("Blue Cube"))
{
target.rotate(0, intensity, 0);//rotate right
}
}
else
{
System.out.println("Selection: Nothing.");
}
}
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
any help to solving this issue would be greatly appreciated, thank you