1. Carl Ådahl
  2. gembobble

Commits

Carl Ådahl  committed 9bf699c

Doing Actor initialization in new(), removed init().
Switched the meaning of attach() and renamed it attachedTo(). Meant to be
chained onto a spawn() call.

  • Participants
  • Parent commits 7c4ccf7
  • Branches default

Comments (0)

Files changed (2)

File src/actor.lua

View file
 end
 
 function Actor.new(t, x, y)
-	local self = {}
+	local self = 
+	{
+		uid = nextUid(),
+		type = t,
+		dt = 0,
+		states = {}
+	}
 
 	local properties = 
 	{ 
 		end
 	})
 
-	-- Initialize the actor.
-	function self.init()
-
-		self.uid = nextUid()
-		self.type = t 
-		self.dt = 0
-		self.states = {}
-		self.drawPriority = 0
-		self.sfx = {}
-
-	end
-
 	-- Attach another actor to this one, making it stay positioned the same, relatively.
-	-- Optionally supply an x,y offset that will be kept.
-	function self.attach(other, offsetx, offsety)
-		other.getX = function() return self.getX() + (offsetx or 0) end
-		other.getY = function() return self.getY() + (offsety or 0) end
-		return other
+	-- Optionally supply an x,y offset that will be maintained.
+	function self.attachTo(parent, offsetx, offsety)
+		self.getX = function() return parent.getX() + (offsetx or 0) end
+		self.getY = function() return parent.getY() + (offsety or 0) end
+		return self
 	end
 
 	-- doFor(time, func, ...)	
 		return self.dt
 	end
 
-	self.init()
 	return self
 end
 

File src/ball.lua

View file
 	
 	function s.init()
 		s.color = color
-		shadow = s.attach(world.spawn(BallShadow.new(s)))
---		shine = s.attach(world.spawn(BallShine.new(s)))
+		shadow = world.spawn(BallShadow.new(s)).attachTo(s)
+--		shine = world.spawn(BallShine.new(s)).attachTo(s)
 	end
 	
 	function s.getX()