Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue May 1, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 30 Aug 2010 at 8:35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant