List of usage examples for com.badlogic.gdx.utils Timer scheduleTask
public void scheduleTask(Task task, float delaySeconds)
From source file:be.ac.ucl.lfsab1509.bouboule.game.body.Bonus.java
License:Open Source License
/** * Constructor for a Bonus object /*from ww w. ja v a2 s .c o m*/ * @param px/py : initial position * @param angle : initial rotation * @param texRegionPath : Path to the image file * @param jsonFile : Path to the jsonFile if needed ( "" else) * @param jsonName : jsonName of the object ( must match the json file attribute ) * * public Bonus( final float px, final float py, * final float angle, final String texRegionPath, * final String jsonFile, final String jsonName, final short bonusType) */ public Bonus(final float angle, final String texRegionPath, final String jsonFile, final String jsonName, final Entity.BonusType bonusType) { super(); int size = GlobalSettings.ARENAWAYPOINTALLOW.size(); MapNode node = GlobalSettings.ARENAWAYPOINTALLOW.get(random.nextInt(size)); Vector2 pos = new Vector2(node.xToPixel() - 32, node.yToPixel() - 32); Vector2 radius = new Vector2(node.weightToPixel() * random.nextFloat(), 0); radius.rotate(random.nextInt(359)); pos.add(radius); this.texture = new TextureRegion(new Texture(texRegionPath)); this.sprite = new Sprite(texture); MakeBody(0, 0, 0, BodyType.StaticBody, 0, 0, true, pos, angle, jsonFile, jsonName, GraphicManager.convertToGame(texture.getRegionWidth())); //Ensure that the object don't rotate. body.setFixedRotation(true); //Create the userData of type Bonus and bonusType this.entity = new Entity(Entity.BONUS, true, bonusType); body.setUserData(this.entity); //Ensure that the body image position is set on the origin defined by //the jsonFile if (origin != null) { pos = positionVector.cpy(); pos = pos.sub(origin); sprite.setPosition(pos.x, pos.y); sprite.setOrigin(origin.x, origin.y); sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees); } // removed the bonus after a delay Timer.Task task = new Timer.Task() { @Override public void run() { entity.setAlive(false); } }; Timer timer = new Timer(); timer.scheduleTask(task, 10f); }