Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ekit.castles.war.controller
- import java.util.ArrayList
- import com.badlogic.gdx.physics.box2d.joints.DistanceJointDef
- import com.ekit.castles.war.model.Model
- /**
- * @author Konstant
- */
- class WorldPostActionController {
- private var destroyrequests = new ArrayList[DestroyDef]()
- private var djointrequests = new ArrayList[DistanceJointDef]()
- /**Destroy body before next box2d world step*/
- def requestDestroy(destroy: DestroyDef) = {
- destroyrequests.add(destroy)
- }
- /**Create new distance joint before next box2d world step*/
- def requestDistanceJoint(joint: DistanceJointDef) = {
- djointrequests.add(joint)
- }
- /**Process all requests and clear requests arrays*/
- def Process = {
- //Process destroy requests
- if (!destroyrequests.isEmpty()) {
- for (request <- destroyrequests.toArray(new Array[DestroyDef](1))) {
- request.body.setActive(false)
- Model.getGameWorld.world destroyBody request.body
- }
- destroyrequests clear ()
- }
- //Process distence joints requests
- if (!djointrequests.isEmpty()) {
- for (request <- djointrequests.toArray(new Array[DistanceJointDef](1))) {
- request.bodyA.setActive(false)
- request.bodyB.setActive(false)
- Model.getGameWorld.world createJoint request
- request.bodyA.setActive(true)
- request.bodyB.setActive(true)
- }
- djointrequests clear ()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement