java - Issues with update method in Android Studio LibGDX -


i'm trying call update method every time amount of time passes, destroys , adds new obstacle, game loop. however, when it, series of errors:

error:(146, 8) gradle: error: illegal start of expression  error:(146, 16) gradle: error: illegal start of expression  error:(146, 32) gradle: error: ';' expected  error:(149, 23) gradle: error: ';' expected  error:(151, 31) gradle: error: '.class' expected  error:(151, 40) gradle: error: illegal start of expression  error:(151, 41) gradle: error: ';' expected 

here's code seems causing problem:

public void update(float deltatime) {         texture playertexture = game.getmanager().get("player.png");         texture floortexture = game.getmanager().get("floor.png");         texture overfloortexture = game.getmanager().get("overfloor.png");         texture overfloor2texture = game.getmanager().get("overfloor2.png");         texture obstacletexture = game.getmanager().get("obstacle.png");         texture obstacle2texture = game.getmanager().get("obstacle2.png");          float timer = 0;         float spawntime = 4f;         private void spawnentity();         {             //increment timer duration since previous frame             float timer += gdx.graphics.getrawdeltatime();             //compare spawntime             if (timer >= float spawntime)             {                 //spawn object                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture, 0, 1000, 1));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,8, 10 ,5));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,10, 10 ,8));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,34 , 3 ,5));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,19 , 8 ,4));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,24 , 8 ,1.5f));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,27 , 5 , 2));                 obstaclelist.add(new obstacleentity(world, floortexture, overfloortexture, overfloor2texture ,25, 10 ,20));                 //but want spawn on right, outside of screen view.                  //this right side of vp in world. depending how draw can add more it.                 float spawnx = camera.position.x + camera.viewportwidth / 2;                 //then use spawn object, since hardcoded stuff have no idea put it.                  //now reset timer                 timer-= spawntime;                  //and perhaps randomize spawntime? (between 2 , 4 seconds)                 random random;                 spawntime = random.nextfloat() * 2 + 2;             }         } 

here's code gamescreen class:

package com.circlecrashavoider;  import com.badlogic.gdx.gdx; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.math.vector2; import com.badlogic.gdx.physics.box2d.contact; import com.badlogic.gdx.physics.box2d.contactimpulse; import com.badlogic.gdx.physics.box2d.contactlistener; import com.badlogic.gdx.physics.box2d.manifold; import com.badlogic.gdx.physics.box2d.world; import com.badlogic.gdx.scenes.scene2d.stage; import com.badlogic.gdx.utils.viewport.fitviewport; import com.circlecrashavoider.entities.floorentity; import com.circlecrashavoider.entities.obstacleentity; import com.circlecrashavoider.entities.obstacleentity2; import com.circlecrashavoider.entities.playerentity;  import java.util.arraylist; import java.util.list; import java.util.objects; import java.util.random;  /**  * created felipe on 2/22/2016.  */  public class gamescreen extends basescreen {      private stage stage;      private world world;      private playerentity player;      private list<floorentity> floorlist = new arraylist<floorentity>();      private list<obstacleentity> obstaclelist = new arraylist<obstacleentity>();      private list<obstacleentity2> obstacle2list = new arraylist<obstacleentity2>();      public gamescreen(maingame game) {         super(game);         stage = new stage(new fitviewport(1024, 620));         world = new world(new vector2(0, -10), true);          world.setcontactlistener(new contactlistener() {              private boolean arecollided(contact contact, object usera, object userb) {                 return (contact.getfixturea().getuserdata().equals(usera) && contact.getfixtureb().getuserdata().equals(userb)) ||                         (contact.getfixturea().getuserdata().equals(userb) && contact.getfixtureb().getuserdata().equals(usera));             }              @override             public void begincontact(contact contact) {                 if (arecollided(contact, "player", "floor")) {                     player.setjumping(false);                     if (gdx.input.istouched()) {                         player.setmustjump(true);                     }                 }                  if (arecollided(contact, "player", "obstacle")) {                         player.setalive(false);                     system.out.println("game over");                  }                  if (arecollided(contact, "player", "obstacle2")) {                     player.setalive(false);                     system.out.println("game over");                 }             }              @override             public void endcontact(contact contact) {              }              @override             public void presolve(contact contact, manifold oldmanifold) {              }              @override             public void postsolve(contact contact, contactimpulse impulse) {              }         });     }      @override     public void show() {         texture playertexture = game.getmanager().get("player.png");         texture floortexture = game.getmanager().get("floor.png");         texture overfloortexture = game.getmanager().get("overfloor.png");         texture overfloor2texture = game.getmanager().get("overfloor2.png");         texture obstacletexture = game.getmanager().get("obstacle.png");         texture obstacle2texture = game.getmanager().get("obstacle2.png");         player = new playerentity(world, playertexture, new vector2(1, 2));          (floorentity floor : floorlist) {             stage.addactor(floor);         }         (obstacleentity obstacle : obstaclelist) {             stage.addactor(obstacle);             stage.addactor(player);         }         (obstacleentity2 obstacle2 : obstacle2list) {             stage.addactor(obstacle2);         }     }      public void update(float deltatime) {         texture playertexture = game.getmanager().get("player.png");         texture floortexture = game.getmanager().get("floor.png");         texture overfloortexture = game.getmanager().get("overfloor.png");         texture overfloor2texture = game.getmanager().get("overfloor2.png");         texture obstacletexture = game.getmanager().get("obstacle.png");         texture obstacle2texture = game.getmanager().get("obstacle2.png");          float timer = 0;         float spawntime = 4f;         private void spawnentity();         {             //increment timer duration since previous frame             float timer += gdx.graphics.getrawdeltatime();             //compare spawntime             if (timer >= float spawntime)             {                 //spawn object                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture, 0, 1000, 1));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,8, 10 ,5));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,10, 10 ,8));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,34 , 3 ,5));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,19 , 8 ,4));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,24 , 8 ,1.5f));                 floorlist.add(new floorentity(world, floortexture, overfloortexture,overfloor2texture ,27 , 5 , 2));                 obstaclelist.add(new obstacleentity(world, floortexture, overfloortexture, overfloor2texture ,25, 10 ,20));                 //but want spawn on right, outside of screen view.                  //this right side of vp in world. depending how draw can add more it.                 float spawnx = camera.position.x + camera.viewportwidth / 2;                 //then use spawn object, since hardcoded stuff have no idea put it.                  //now reset timer                 timer-= spawntime;                  //and perhaps randomize spawntime? (between 2 , 4 seconds)                 random random;                 spawntime = random.nextfloat() * 2 + 2;             }         }      @override     public void render(float delta) {         gdx.gl20.glclearcolor(0.5f, 0.6f, 1, 3f);         gdx.gl20.glclear(gl20.gl_color_buffer_bit);          stage.act();         world.step(delta, 6 ,2);         stage.draw();     }      @override     public void dispose() {         stage.dispose();         world.dispose();     } } 

take @ fragment of code:

    float timer += gdx.graphics.getrawdeltatime();     //compare spawntime     if (timer >= float spawntime)     {         //spawn object 

you missing brackets arround float word - trying use (float) (casting operator) way causes exception.

it should be

    if (timer >= (float)spawntime) 

or rather

    if (timer >= spawntime) 

since spawntime of float type


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -