From b262cb3eec1a797832d168f9e6d144468fb48c1d Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 01:35:43 +0100 Subject: Initializers in PhysicalBody, Hero and Sprite --- not/Sprite.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'not/Sprite.lua') diff --git a/not/Sprite.lua b/not/Sprite.lua index 905816b..6342f60 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -12,9 +12,7 @@ Sprite.__index = Sprite -- Constructor of `Sprite`. function Sprite:new (imagePath) local o = setmetatable({}, self) - if type(imagePath) == "string" then - o:setImage(self.newImage(imagePath)) - end + o:init(imagePath) return o end @@ -23,6 +21,13 @@ function Sprite:delete () self.image = nil end +-- Initializes new Sprite instance. +function Sprite:init (imagePath) + if type(imagePath) == "string" then + self:setImage(Sprite.newImage(imagePath)) + end +end + -- Creates new Image object from path. Key-colours two shades of green. Static. function Sprite.newImage (path) local imagedata = love.image.newImageData(path) -- cgit v1.1