yash0924 / rokon

Automatically exported from code.google.com/p/rokon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[PATCH] Enhancement, adds methods to DrawableObject: isLeftOfScreen(), isRightOfScreen(), isAboveScreen(), isBelowScreen() #154

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Building on the scene size abstractions in #153, this patch adds methods to 
DrawableObject to determine where an object has gone out of its scene.

--- a/src/com/stickycoding/rokon/DrawableObject.java
+++ b/src/com/stickycoding/rokon/DrawableObject.java
@@ -707,4 +707,59 @@ public class DrawableObject extends BasicGameObject 
implements Drawable, Updatea
    public void removeColourBuffer() {
        colourBuffer = null;
    }
+
+
+    /**
+     * Returns true if the object is being drawn and is located off
+     * the left edge of the visible screen.
+     */
+    public boolean isLeftOfScreen() {
+        if(parentLayer == null) {
+          return false;
+        }
+        float maxSize = width;
+        if(height > width) maxSize = height;
+        
+        return getX() + maxSize < parentScene.getX();
+    }
+
+    /**
+     * Returns true if the object is being drawn and is located off
+     * the right edge of the visible screen.
+     */
+    public boolean isRightOfScreen() {
+        if(parentLayer == null) {
+          return false;
+        }
+        
+        return getX() > parentScene.getX() + parentScene.getWidth();
+    }
+
+    /**
+     * Returns true if the object is being drawn and is located above
+     * the top edge of the visible screen.
+     */
+    public boolean isAboveScreen() {
+        if(parentLayer == null) {
+          return false;
+        }
+        float maxSize = width;
+        if(height > width) maxSize = height;
+        
+        return getY() + maxSize < parentScene.getY();
+    }
+
+    /**
+     * Returns true if the object is being drawn and is located below
+     * the bottom edge of the visible screen.
+     */
+    public boolean isBelowScreen() {
+        if(parentLayer == null) {
+          return false;
+        }
+        
+        return getY() > parentScene.getY() + parentScene.getHeight();
+    }
+
+   
 }

Original issue reported on code.google.com by pjleg...@gmail.com on 30 Aug 2010 at 8:35