|
22 | 22 | */ |
23 | 23 | public class Component { |
24 | 24 |
|
25 | | - protected int layer = 100; |
| 25 | + protected int layer = 0; |
26 | 26 | protected String tag = ""; |
27 | 27 | protected float angle = 0; |
28 | 28 | protected boolean visible = true; |
@@ -196,18 +196,20 @@ public void translate(Vector2 towards){ |
196 | 196 | if(collider!=null){ |
197 | 197 | Collider addedX = new Collider(); |
198 | 198 | addedX.localVertices = collider.getLocalVertices(); |
199 | | - addedX.setPosition(getPosition().add(towards.removeY())); |
| 199 | + addedX.setPosition(collider.getPosition().add(towards.removeY())); |
200 | 200 | addedX.setScale(addedX.getScale().subtract(1)); |
201 | 201 | addedX.updateVertices(); |
202 | 202 |
|
203 | 203 | Collider addedY = new Collider(); |
204 | 204 | addedY.localVertices = collider.getLocalVertices(); |
205 | | - addedY.setPosition(getPosition().add(towards.removeX())); |
| 205 | + addedY.setPosition(collider.getPosition().add(towards.removeX())); |
206 | 206 | addedY.setScale(addedY.getScale().subtract(1)); |
207 | 207 | addedY.updateVertices(); |
208 | 208 |
|
209 | 209 | // all components in the scene |
210 | 210 | for ( Component c : JavaGameEngine.getSelectedScene().getComponents1() ){ |
| 211 | + if(c.getPosition().getZ() != getPosition().getZ()) continue; |
| 212 | + |
211 | 213 | if(c != this && JavaGameEngine.getSelectedScene().inside(c)){ // don't check us |
212 | 214 | for ( Component cc : c.getChildren(new Collider()) ){ |
213 | 215 | Collider otherCollider = (Collider) cc; |
@@ -242,9 +244,9 @@ else if(otherCollider.isTrigger()){ |
242 | 244 | try{ |
243 | 245 | Vector2 vel = ((PhysicsBody) getChild(new PhysicsBody())).velocity; |
244 | 246 | ((PhysicsBody) getChild(new PhysicsBody())).response(event); |
245 | | - if(((PhysicsBody) getChild(new PhysicsBody())).velocity.getX() == vel.getX()){ |
| 247 | + if(this.<PhysicsBody>getChild().velocity.getX() == vel.getX()){ |
246 | 248 | //Debug.log("zeor"); |
247 | | - ((PhysicsBody) getChild(new PhysicsBody())).velocity.setX(0); |
| 249 | + this.<PhysicsBody>getChild().velocity.setX(0); |
248 | 250 | } |
249 | 251 | }catch (Exception e){} |
250 | 252 | } |
@@ -294,7 +296,7 @@ else if(otherCollider.isTrigger()){ |
294 | 296 | public void setPosition(Vector2 position) { |
295 | 297 | //this.lastPosition = this.position; |
296 | 298 |
|
297 | | - if(getParent()!=null){ |
| 299 | + if(getParent() != null){ |
298 | 300 | this.position = position.add(parentOffset).add(rotOffset); |
299 | 301 |
|
300 | 302 | }else{ |
@@ -463,13 +465,14 @@ public LinkedList<Component> getAllChildren(Component type){ |
463 | 465 | } |
464 | 466 |
|
465 | 467 | public <T>T getChild(){ |
| 468 | + T t = null; |
466 | 469 | for (Component child : this.children){ |
467 | 470 | try{ |
468 | | - return ((T)child); |
| 471 | + t = ((T)child); |
469 | 472 | } |
470 | 473 | catch (Exception e){} |
471 | 474 | } |
472 | | - return null; |
| 475 | + return t; |
473 | 476 | } |
474 | 477 | /** |
475 | 478 | * @param type the specified type of the children to be returned |
|
0 commit comments