Sure!
Here is where the actual sprite creation is being done. (I was also getting some seam weirdness using the mask to shorten the last block, but the problem in the screenshot seems to exist outside of that and I suspect is the same problem, since the masking works perfectly in iPhone4 mode.)
Any texture passed to this function will be 32x32 (with a 64x64 @2 version). The mask is (as the filename says) a 40x40 image that’s all white except for a 4-pixel-wide block border with an @2 version.
[lua]–Constructor helper function that creates the sprites with the passed texture name.
– Can be called by derived classes with different textures after passing false for bInitSprites to the constructor
function Floor:_InitRectSprites(dLength, sTextureName)
–Make the RectSprite for each section
self._m_vRectSprites = {}
local nNumSections = math.ceil(dLength / Floor._v2dSectionSize.x)
for i = 1, nNumSections do
self._m_vRectSprites[i] = RectSprite.New(sTextureName, Vec2D.New(self._m_v2dPos.x + ((i - 1) * Floor._v2dSectionSize.x), self._m_v2dPos.y))
SpriteManager.Instance:AddRectSpriteToLayer(self._m_vRectSprites[i], SpriteManager.LEVEL_OBJECTS)
end
–We must mask the last section to exactly get the length
local nLastSectionLength = Floor._v2dSectionSize.x - ((nNumSections * Floor._v2dSectionSize.x) - dLength)
self._m_vRectSprites[nNumSections]:SetMask(graphics.newMask(“Masks/WhiteWith4BlackBorder_40x40.png”))
self._m_vRectSprites[nNumSections]:SetMaskOffset(Vec2D.New(-(Floor._v2dSectionSize.x - nLastSectionLength), 0))
end[/lua]
Here is the RectSprite constructor called in that function:
[lua]–Constructor
–sImageFileName is the image filename to load and v2dPos is the initial upper-left position
function RectSprite.New(sImageFileName, v2dPos)
–Make new object
local newRectSprite = {}
setmetatable(newRectSprite, RectSprite)
–Get and save the image’s unscaled size, if it hasn’t already been loaded
if RectSprite._ImageFileSizes[sImageFileName] == nil then
local image = display.newImage(sImageFileName)
if image == nil then
DebugFunctions.Traceback()
end
RectSprite._ImageFileSizes[sImageFileName] = Vec2D.New(image.width, image.height);
display.remove(image)
end
newRectSprite._m_v2dSize = RectSprite._ImageFileSizes[sImageFileName];
–Make the dynamically-scaled image
newRectSprite._m_ImageRect = display.newImageRect(sImageFileName, newRectSprite._m_v2dSize.x, newRectSprite._m_v2dSize.y)
–Init _m_v2dPosition and then set it to the passed position
newRectSprite._m_v2dPosition = Vec2D.New()
newRectSprite:SetPos(v2dPos)
return newRectSprite
end[/lua]
And, finally, here’s the SpriteManager function also called in the original function that actually inserts the image into a display group:
[lua]–Adds the passed RectSprite to the passed layer. Automatically removes it from it’s previous layer, if it already existed.
function SpriteManager:AddRectSpriteToLayer(pRectSprite, nLayer)
–Validate layer value
if DEBUG then
assert(nLayer >= 1 and nLayer <= SpriteManager.NUM_LAYERS)
end
–Remove from previous layer, if necessary
if self._m_mSpritesToDisplayGroups[pRectSprite] ~= nil then
self:RemoveSprite(pRectSprite)
end
–Insert into layer and save where it was put
self._m_vDisplayGroups[nLayer]:insert(pRectSprite._m_ImageRect)
self._m_mSpritesToDisplayGroups[pRectSprite] = nLayer
end[/lua]
Thanks for the help and let me know if you need anymore info! [import]uid: 145887 topic_id: 26167 reply_id: 106114[/import]