This site requires JavaScript, please enable it in your browser!
Greenfoot back
Aspire_Seven
Aspire_Seven wrote ...

2014/2/22

<identifier> expected error

Aspire_Seven Aspire_Seven

2014/2/22

#
I am making a video game scroll world and so far i have typed this for the actor. It allows them to move left and right and jump. However, so far with compiling, when i get to the part that says " private GreenfootImage_playerStart= new GreenfootImage("Images/Idle/Idle_0.png");" it gives the <identifier> expected error. what am i doing wrong? thanks! =) import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Player here. * * @author (your name) * @version (a version number or a date) */ public class Player extends Animal { //Basics physics variables private double positionX; private double positionY; private double velocityX=0; private double velocityY=0; private double accelerationX=0; private double accelerationY=0; //Force values private double gravityY=0.1; private double jumpForce=3.5; private GreenfootImage_playerStart= new GreenfootImage("Images/Idle/Idle_0.png"); private int speed = 2; public void addedToWorld(Worldw){ //we set out position to the position which we were added to the world at. positionX=getX(); positionY=getY(); } /** * Act-do whatever the person wants to do. This method is called * whenever the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //Apply forces to change acceleration to move the person { If(Greenfoot.isKeyDown("right")) move (-30); If(Greenfoot.isKeyDown("left")) move (30); } applygravity(); applyjumpForce(); velocityX+=accelerationX; velocityY+=accelerationY; positionX+=velocityX; positionY+=velocityY; accelerationX=0; accelerationY=0; SetLocation((int)postionX,(int)postionY); } /** * Accelerates the person downwards except for when they are on a platform */ private void apply Gravity(){ //check for collision with platform Actor coll= getOneIntersectingObject(Platform.class); if(coll==null){ //This is run when the person is not touching a platform //This code adds gravity to out total acceleration. accelerationY+=gravityY; }else{ //This is run once we hit a platform //we make our person stop moving in the Y direction. (up/down direction). velocityY=0; } } /** * Accelerates the person upwards if space is pressed and we are on a platform */ public void applyjumpForce(){ Action coll = getOneIntersectionObject(Platform.class); if(coll!=null){ //This is run when the person is touching a platform If(Greenfoot.isKeyDown("Space")){ accelerationY-=jumpForce; } } } }
danpost danpost

2014/2/22

#
The underscore between 'GreenfootImage' and 'playerStart' make it appear to the compiler like a field name (since there is no class called 'GreenfootImage_playerStart'. But, if it is a field name, then the compiler would need to know what type of field it is (which it then believes is not given -- the <identifier>). Either remove the underscore or put a space between 'GreenfootImage' and '_playerStart' or add 'GreenfootImage' (the type) before 'GreenfootImage_playerStart'.
Aspire_Seven Aspire_Seven

2014/2/22

#
That worked. And I managed to sort out all the other errors that appeared after that. Thanks!
You need to login to post a reply.