T-Bone wrote:I just realized something. If I change "bottom" to a larger value, should that mean that the rectangle moves down, or that it becomes taller? That's not obvious to me. Maybe functions like "moveToBottom" and "expandToBottom" are better for clarity.
Pygame rect reference wrote:
Assigning to size, width or height changes the dimensions of the rectangle; all other assignments move the rectangle without resizing it. Notice that some attributes are integers and others are pairs of integers.
I personally find this less than appealing design, but to each their own, i guess Also, this be löve, so it can be implemented differently, better even.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
function Rect:new(x,y,w,h)
local self = setmetatable({}, Rect)
self.x = x
self.y = y
self.width = w
self.height = h
return self
end
-- and at the end of the file return this
return setmetatable({}, {__call=Rect.new})
Though my constructors are usually local, and if needed, i create a copy method that accesses the constructor.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
local function newRect(x, y, w, h)
...
end
...
return newRect
I don't like the second one that much but it works.
There was a reason why I used __call in addition to some other stuff sometimes in the past, but I don't know it anymore :S
If you wanted to return a table full of "class" functions, then that would be a solution, calling the table calling the constructor.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
I actually implemented the bounding box with the .left or .bottom member thing, if people are interested they can see it here: http://pastebin.com/SG8PgtfM