Problems with Sprite migration

Hi guys, I have a problem that I have been unable to solve for awhile now, it involves the migration from the old sprite library to the new one for an old project, some of the sequences do not play correctly, I am using graphics 1.0 compatibility mode for my project
 
my migrated gameAnim.lua

-- player class definition gameAnim = {} gameAnim.\_\_index = gameAnim -- only the last entry in the table for each attrAnimList[animType] gets played function gameAnim.create(anim) local animType = anim.animType local pos = anim.pos local attrAnim = require("cfg.attrAnimList") local this = {} local frameStart = 1 this.displayGroup = display.newGroup() this.spriteList = {} this.curSpriteNum = 1 -- create spriteSheets for i = 1, #attrAnim[animType] do this.ImageSheet = nil if display.contentScaleX == 0.5 then this.ImageSheet = graphics.newImageSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite2x, {width = attrAnim[animType][i].size.x \* 2, height = attrAnim[animType][i].size.y \* 2, numFrames = attrAnim[animType][i].numFrames}) else this.ImageSheet = graphics.newImageSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite, {width = attrAnim[animType][i].size.x, height = attrAnim[animType][i].size.y, numFrames = attrAnim[animType][i].numFrames}) end this.sequenceData = { { name = attrAnim[animType][i].name, sheet = this.ImageSheet,frames = attrAnim[animType][i].frames, time = attrAnim[animType][i].duration, loopCount = attrAnim[animType][i].loop, loopDirection = "forward" } } this.spriteList[i] = { name = attrAnim[animType][i].name } end this.curSprite = display.newSprite( this.ImageSheet, this.sequenceData ) if display.contentScaleX == 0.5 then local scale = this.curSprite.xScale if scale \< 0 then this.curSprite.xScale = -0.5; else this.curSprite.xScale = 0.5; end this.curSprite.yScale = 0.5 end if (this.curSprite) == nil then print("CurSprite = nil") end this.curSprite:setSequence( this.spriteList[1].name ) this.curSprite:setFrame(1) this.curSprite:play() print("Anim Rect = " .. tostring(attrAnim[animType].colRect)) if attrAnim[animType].colRect then local rect = attrAnim[animType].colRect local size = attrAnim[animType].size print("Collision Rect exist!!!!") local colRect = { rect.x - size.x \* 0.5, rect.y - size.y \* 0.5, rect.x - size.x \* 0.5 + rect.w, rect.y - size.y \* 0.5, rect.x - size.x \* 0.5 + rect.w, rect.y + rect.h - size.y \* 0.5, rect.x - size.x \* 0.5, rect.y + rect.h - size.y \* 0.5, } this.colRect = colRect end -- insert to display group this.displayGroup:insert( this.curSprite ) -- switch animation this.switchNextAnim = function(anim) print("Switch animation") --if anim == this.curAnim then return end if anim == nil then this.curSpriteNum = this.curSpriteNum + 1 else this.curSpriteNum = anim end print("\nCurSprite = \n" .. this.curSpriteNum) if this.curSpriteNum \> #this.sequenceData then print("Reached end of list, switch to first animation") this.curSpriteNum = 1 --return end print("\n CURRENT SPRITE SEQUENCE NUMBER : " .. tostring(this.curSpriteNum) .. "\n") print("\n CURRENT SPRITE SEQUENCE NAME : " .. tostring(this.spriteList[this.curSpriteNum].name) .. "\n") --this.curAnim = anim if display.contentScaleX == 0.5 then local scale = this.curSprite.xScale if scale \< 0 then this.curSprite.xScale = -0.5 else this.curSprite.xScale = 0.5 end this.curSprite.yScale = 0.5 end this.curAnim = this.spriteList[this.curSpriteNum].name this.curSprite:pause() this.curSprite:setSequence(this.curAnim) -- NOTE: MUST RESET THE CURRENT FRAME! this.curSprite:setFrame(1) this.curSprite:play() end this.flipAnim = function() local scale = this.curSprite.xScale scale = -scale this.curSprite.xScale = scale if display.contentScaleX == 0.5 then if scale \< 0 then this.curSprite.xScale = -0.5 else this.curSprite.xScale = 0.5 end this.curSprite.yScale = 0.5 end end -- check if anim is flipped this.isFlipped = function() if this.curSprite.xScale \< 0 then return true else return false end end --this.displayGroup.this = this setmetatable(this, gameAnim) return this end -- send entity command function gameAnim:sendCmd(cmd, paramList) -- get data if cmd == ENT\_CMD.DESTROY then print("DESTROYING gameAnim") self.spriteList = nil -- remove display group print("----disposing \<gameAnim\> displayGroup") self.displayGroup:removeSelf() self.displayGroup = nil elseif cmd == ENT\_CMD.FLIP\_ANIM then if paramList == "isFlipped" then return self.isFlipped() else print("Flip animation") self.flipAnim() end elseif cmd == ENT\_CMD.SWITCH\_NEXT\_ANIM then self.switchNextAnim(paramList) elseif cmd == ENT\_CMD.PAUSE\_ANIM then --if paramList then if paramList == true then self.curSprite:pause() print("Anim paused") else self.curSprite:play() print("Anim play") end -- end end end

The original gameAnim.lua 

-- player class definition gameAnim = {} gameAnim.\_\_index = gameAnim function gameAnim.create(anim) local animType = anim.animType local pos = anim.pos require("sprite") local attrAnim = require("cfg.attrAnimList") local this = {} this.displayGroup = display.newGroup() --this.displayGroup.x = pos.x --this.displayGroup.y = pos.y --this.displayGroup.sortType = 0 this.spriteList = {} this.curSpriteNum = 1 --[[-- cater for @2X if display.contentScaleX == 0.5 then this.spriteIdle = sprite.newSpriteSheet(path .. "idle@2x.png", 140, 218) this.spriteWalk = sprite.newSpriteSheet(path .. "running@2x.png", 140, 218) else this.spriteIdle = sprite.newSpriteSheet(path .. "idle.png", 70, 109) this.spriteWalk = sprite.newSpriteSheet(path .. "running.png", 70, 109) end]]-- -- create spriteSheets for i = 1, #attrAnim[animType] do --print(attrAnim[animType][i].sprite) local curSprite = nil if display.contentScaleX == 0.5 then curSprite = sprite.newSpriteSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite2x, attrAnim[animType][i].size.x \* 2, attrAnim[animType][i].size.y \* 2) else curSprite = sprite.newSpriteSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite, attrAnim[animType][i].size.x, attrAnim[animType][i].size.y) end this.spriteList[i] = { name = attrAnim[animType][i].name, sheet = curSprite, frames = attrAnim[animType][i].frames, } end -- set sprites local spriteSet = sprite.newSpriteMultiSet(this.spriteList) -- add sprites local frameStart = 1 for i = 1, #attrAnim[animType] do sprite.add(spriteSet, attrAnim[animType][i].name, frameStart, #attrAnim[animType][i].frames, attrAnim[animType][i].duration, attrAnim[animType][i].loop) frameStart = frameStart + #attrAnim[animType][i].frames end this.curSprite = sprite.newSprite(spriteSet) if display.contentScaleX == 0.5 then local scale = this.curSprite.xScale if scale \< 0 then this.curSprite.xScale = -0.5 else this.curSprite.xScale = 0.5 end this.curSprite.yScale = 0.5 end this.curSprite:prepare(this.spriteList[1].name) this.curSprite.currentFrame = 1 this.curSprite:play() print("Anim Rect = " .. tostring(attrAnim[animType].colRect)) if attrAnim[animType].colRect then local rect = attrAnim[animType].colRect local size = attrAnim[animType].size print("Collision Rect exist!!!!") local colRect = { rect.x - size.x \* 0.5, rect.y - size.y \* 0.5, rect.x - size.x \* 0.5 + rect.w, rect.y - size.y \* 0.5, rect.x - size.x \* 0.5 + rect.w, rect.y + rect.h - size.y \* 0.5, rect.x - size.x \* 0.5, rect.y + rect.h - size.y \* 0.5, } this.colRect = colRect end -- insert to display group this.displayGroup:insert(this.curSprite) -- switch animation this.switchNextAnim = function(anim) print("Switch animation") --if anim == this.curAnim then return end if anim == nil then this.curSpriteNum = this.curSpriteNum + 1 else this.curSpriteNum = anim end print("CurSprite = " .. this.curSpriteNum) if this.curSpriteNum \> #this.spriteList then print("Reached end of list, switch to first animation") this.curSpriteNum = 1 --return end print(tostring(this.spriteList[this.curSpriteNum].name)) --this.curAnim = anim if display.contentScaleX == 0.5 then local scale = this.curSprite.xScale if scale \< 0 then this.curSprite.xScale = -0.5 else this.curSprite.xScale = 0.5 end this.curSprite.yScale = 0.5 end this.curAnim = this.spriteList[this.curSpriteNum].name this.curSprite:pause() this.curSprite:prepare(this.curAnim) -- NOTE: MUST RESET THE CURRENT FRAME! this.curSprite.currentFrame = 1; this.curSprite:play() end this.flipAnim = function() local scale = this.curSprite.xScale scale = -scale this.curSprite.xScale = scale if display.contentScaleX == 0.5 then if scale \< 0 then this.curSprite.xScale = -0.5; else this.curSprite.xScale = 0.5; end this.curSprite.yScale = 0.5 end end -- check if anim is flipped this.isFlipped = function() if this.curSprite.xScale \< 0 then return true else return false end end --this.displayGroup.this = this setmetatable(this, gameAnim) unrequire("sprite") return this end -- send entity command function gameAnim:sendCmd(cmd, paramList) -- get data if cmd == ENT\_CMD.DESTROY then print("DESTROYING gameAnim") for i = 1, #self.spriteList do self.spriteList[i].sheet:dispose() self.spriteList[i].sheet = nil print("----disposing \<" .. self.spriteList[i].name.. "\> animation") end self.spriteList = nil -- remove display group print("----disposing \<gameAnim\> displayGroup") self.displayGroup:removeSelf() self.displayGroup = nil elseif cmd == ENT\_CMD.FLIP\_ANIM then if paramList == "isFlipped" then return self.isFlipped() else print("Flip animation") self.flipAnim() end elseif cmd == ENT\_CMD.SWITCH\_NEXT\_ANIM then self.switchNextAnim(paramList) elseif cmd == ENT\_CMD.PAUSE\_ANIM then --if paramList then if paramList == true then self.curSprite:pause() print("Anim paused") else self.curSprite:play() print("Anim play") end -- end end end

a snippet my Anim Attribute list

local attrAnimList = {} ... attrAnimList[ANIM\_TYPE.LIFT] = { size = {x = 130,y = 125}, colRect = {x = 15,y = 20,w = 100,h = 60}, { sprite = "lift.png", sprite2x = "lift@2x.png", size = {x = 130,y = 125}, frames = {3,2,1}, numFrames = 3, name = "lift-close", duration = 1000, loop = 1, }, { sprite = "lift.png", sprite2x = "lift@2x.png", size = {x = 130,y = 125}, frames = {1,2,3}, numFrames = 3, name = "lift-open", duration = 1000, loop = 1, }, } attrAnimList[ANIM\_TYPE.STANDLAMP] = { size = {x = 55,y = 75}, colRect = {x = 20,y = 20,w = 15,h = 25}, { sprite = "Stand\_lamp\_anim.png", sprite2x = "Stand\_lamp\_anim@2x.png", size = {x = 55,y = 75}, frames = {1,1}, numFrames = 3, name = "lamp-off", duration = 800, loop = 1, }, { sprite = "Stand\_lamp\_anim.png", sprite2x = "Stand\_lamp\_anim@2x.png", size = {x = 55,y = 75}, frames = {2,2}, numFrames = 3, name = "lamp-on", duration = 800, loop = 1, }, { sprite = "Stand\_lamp\_anim.png", sprite2x = "Stand\_lamp\_anim@2x.png", size = {x = 55,y = 75}, frames = {3,3}, numFrames = 3, name = "lamp-on-energy", duration = 800, loop = 1, }, } ... return attrAnimList

did i miss out on something or did i do something wrong? I appreciate any help i can get, I also apologize for the messy code

Alright I sort of fixed my problem , by changing the way i call my sequenceData, the sprites mostly play in order, only on the the first time the sprites play the wrong sequence , subsequent times it plays just fine, pardon my formatting

 for i = 1, #attrAnim[animType] do this.ImageSheet = nil if display.contentScaleX == 0.5 then this.ImageSheet = graphics.newImageSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite2x, {width = attrAnim[animType][i].size.x \* 2, height = attrAnim[animType][i].size.y \* 2, numFrames = attrAnim[animType][i].numFrames}) else this.ImageSheet = graphics.newImageSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite, {width = attrAnim[animType][i].size.x, height = attrAnim[animType][i].size.y, numFrames = attrAnim[animType][i].numFrames}) end this.spriteList[i] = { name = attrAnim[animType][i].name, sheet = this.ImageSheet,frames = attrAnim[animType][i].frames, time = attrAnim[animType][i].duration, loopCount = attrAnim[animType][i].loop, loopDirection = "forward" } end this.sequenceData = this.spriteList this.curSprite = display.newSprite( this.ImageSheet, this.sequenceData )

I solved the problem 

Alright I sort of fixed my problem , by changing the way i call my sequenceData, the sprites mostly play in order, only on the the first time the sprites play the wrong sequence , subsequent times it plays just fine, pardon my formatting

 for i = 1, #attrAnim[animType] do this.ImageSheet = nil if display.contentScaleX == 0.5 then this.ImageSheet = graphics.newImageSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite2x, {width = attrAnim[animType][i].size.x \* 2, height = attrAnim[animType][i].size.y \* 2, numFrames = attrAnim[animType][i].numFrames}) else this.ImageSheet = graphics.newImageSheet("images/obstacles/animation/" .. attrAnim[animType][i].sprite, {width = attrAnim[animType][i].size.x, height = attrAnim[animType][i].size.y, numFrames = attrAnim[animType][i].numFrames}) end this.spriteList[i] = { name = attrAnim[animType][i].name, sheet = this.ImageSheet,frames = attrAnim[animType][i].frames, time = attrAnim[animType][i].duration, loopCount = attrAnim[animType][i].loop, loopDirection = "forward" } end this.sequenceData = this.spriteList this.curSprite = display.newSprite( this.ImageSheet, this.sequenceData )

I solved the problem