I’m working on a feature that is suppose to do a skin or texture swap in game, basically I’m going from a bear character to a do character. Code structure I am working with was made a while ago, and this feature had been thought of, so I’m trying to figure a way to do this without a lot of sweeping code changes.
right now my flow kind of works like this
local bearColor = bearTypeArray[selectedBearX][selectedBearyY]
local xCoord = {}
local yCoord = {}
local i = 1
-- locate and delete and tag location for skin change
for x = 1, 6 do
for y = 1, 6 do
if bearTypeArray[x][y] == bearColor then
xCoord[i] = bearObjectArray[x][y].x
yCoord[i] = bearObjectArray[x][y].y
bearObjectArray[x][y]:delete()
i = i + 1
end
end
end
i = 1
ability:AblityTwoClicked(bearTypeArray[selectedBearX][selectedBearY])
--replace missing models
for x = 1, 6 do
for y = 1, 6 do
if bearTypeArray[x][y] == bearColor then
-- create new object
bearTypeArray[x][y] = bear:new(bearTypeArray[x][y], xCoord[i], yCoord[i], false)
i = i + 1
end
end
end
function delete()
self.anim:pause()
self.anim:removeSelf()
end
function AblityTwoClicked(color)
if abilitySlot2 == "changeToDog" then
skinsAndAccessories.ChangeBearToDog(color)
end
end
function ChangeBearToDog(color)
if color == 1 then
-- dispose of current sheet
AnimGirlRedSheet:dispose()
AnimGirlRedSheet = sprite.newSpriteSheet( "atlasGirlRedDog.png", 66, 92 )
redGirl = sprite.newSpriteSet(AnimGirlRedSheet, 1, 5)
sprite.add( redGirl, "idle", 1, 5, 900, 0 )
redGirlWalk = sprite.newSpriteSet(AnimGirlRedSheet, 16, 2)
sprite.add( redGirlWalk, "walk", 16, 2, 200, 0 )
redGirlNo = sprite.newSpriteSet(AnimGirlRedSheet, 21, 11)
sprite.add( redGirlNo, "No", 21, 11, 500, 1 )
redGirlSelect = sprite.newSpriteSet(AnimGirlRedSheet, 31, 6)
sprite.add( redGirlSelect, "Select", 31, 6, 500, 0 )
redGirlJump = sprite.newSpriteSet(AnimGirlRedSheet, 36, 5)
sprite.add( redGirlJump, "Jump", 36, 5, 500, 1 )
redGirlSpawn = sprite.newSpriteSet(AnimGirlRedSheet, 36, 11)
sprite.add( redGirlSpawn, "spawn", 41, 7, 600, 1 )
redGirlWalkUp = sprite.newSpriteSet(AnimGirlRedSheet, 51, 9)
sprite.add( redGirlWalkUp, "Walk", 51, 9, 500, 0)
end
end
Right now I am using the exact names for the new sprite sheet animations that are originally declared at launch of the program, I was hoping by doing this I don’t have put a TON of if statements into the code as that would require a lot more over head.
This code words right up until I get to the AnimGirlRedSheet:dispose() then I get the error “WARNING: Attempting to set property(currentFrame) with nil.” and can’t seem to move past that. [import]uid: 105311 topic_id: 29890 reply_id: 329890[/import]