Commits

Chris Klimas committed 4f4fdf4

Add scale, distort, and origin for Groups

Allows for overall scaling of a scene.

Comments (0)

Files changed (1)

zoetrope/core/group.lua

 	-- sprites at their normal position, set both x and y to 1.
 	translateScale = { x = 1, y = 1 },
 
+	-- Property: scale
+	-- Zooms in or out all drawing operations in the group, centering them with
+	-- respect to the <origin> property.
+	scale = 1,
+
+	-- Property: distort
+	-- Distorts the group's scale, similar to <Sprite.distort>.
+	distort = { x = 1, y = 1 },
+
+	-- Property: origin
+	-- Sets the center point for all scaling operations.
+	origin = { x = 0, y = 0 },
+
 	-- Method: add
 	-- Adds a sprite to the group.
 	--
 		local scrollY = y * self.translateScale.y
 		local appWidth = the.app.width
 		local appHeight = the.app.height
+		local scaled = self.scale ~= 1 or self.distort.x ~= 1 or self.distort.y ~= 1
 
 		if self.effect then
 			if self.effectType == 'screen' then
 				love.graphics.setPixelEffect(self.effect)
 			end
 		end
+
+		if scaled then
+			local scaleX = self.scale * self.distort.x
+			local scaleY = self.scale * self.distort.y
+
+			love.graphics.push()
+			love.graphics.translate(self.origin.x, self.origin.y)
+			love.graphics.scale(scaleX, scaleY)
+			love.graphics.translate(- self.origin.x, - self.origin.y)
+		end
 		
 		for _, spr in self:members() do	
 			if spr.visible then
 				end
 			end
 		end
+
+		if scaled then
+			love.graphics.pop()
+		end
 			
 		if self.effect then
 			if self.effectType == 'screen' then