From 3265575d1e8afcd9892673186db888ae7706bad3 Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Sun, 26 Jan 2014 05:40:08 -0500 Subject: [PATCH] Prevent base menus from extending beyond the boundaries of the application window --- objects/menu.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/objects/menu.lua b/objects/menu.lua index 0b40513..be35b6e 100644 --- a/objects/menu.lua +++ b/objects/menu.lua @@ -91,6 +91,20 @@ function newobject:update(dt) self.largest_item_width = 0 self.largest_item_height = 0 + local screen_width = love.graphics.getWidth() + local screen_height = love.graphics.getHeight() + local sx = self.x + local sy = self.y + local width = self.width + local height = self.height + local x1 = sx + width + if sx + width > screen_width then + self.x = screen_width - width + end + if sy + self.height > screen_height then + self.y = screen_height - self.height + end + if update then update(self, dt) end