Having a problem changing the sequence of my sprite, it doesnt change!

Hello, the problem seems to be kinda complicated but im sure its something simple, I just cant come up with the solution.

I have a sheet, with two animations, one for the walking of the enemy, and one for the falling, so I coded this:

local NormalEnemyOptions = {
        width = 200;
        height = 200;
        numFrames = 14;
–The image is 2800x200, there are 14 frames
    }
    local NormalEnemySheet = graphics.newImageSheet(“NormalEnemySheet .png”, NormalEnemyOptions );
    local WalkingEnemySecuence= {
        name = “Walking”;
        start = 1;
        count = 8;
        time = 550;
        loopCount = 0;
        loopDirection = “forward”;
    }
    local FallingEnemySecuence = {
        name = “Falling”;
        start = 9;
        count = 14;
        time = 550;
        loopCount = 1;
        loopDirection = “forward”;
    } 

So then I set the walking sequence and start playing it:

local self = display.newSprite(NormalEnemySheet , WalkingEnemySecuence);

self.width = 30; self.height = 45; self.xScale = 0.35; self.yScale = 0.35;

self:play();

physics.addBody(self, “kinematic”, {friction = 0.5, bounce = 0.2});

(The Scale, width and height thing is just to adjust it to the game, dont mind it.)

But when I shoot the enemy, I want it to change the animation, so I made a function (Which is called from the main file, because the enemy is a completly apart class)

The function is the following one:

function self:ChangetoFalling()

        self:setSequence(“Falling”);

        print(“The sprite has been changed”)

        self:play();

        print(“PLAAAAAY”)

end

I put those prints there to see if the code its executed, and it is, I just dont know why the animation doesnt change, it is still the same, not a single change, I dont know what else to do, I have been looking everywhere but nobody seems to have this problem.

THANKS A LOT FOR YOUR HELP!

PS:The names of everything are traducted to English so you can understand better, but they are coded in Spanish, so if you find a spanish word its because I forgot to translate it, its not in the code.

Woah, 2800? That’s too big, you won’t run this on any mobile device.

That because you never passed fallingEnemySequence to newSprite. Second parameter for newSprite is table containing tables of sequences. So you must wrap walikingEnemySequence and fallingEnemySequence in one table and then pass it to function.

Thats because Im working with huge files now im designing it, and I will scale them down once the project is finished, just so I can edit them more easily.

Is this bad?

(Also, which sizes do you reccommend? Thanks for any help you can give)

That solved it! Thanks a lot!

1024 px (width or height) is considered max generally. Newer devices can handle even up to 2048px but you are limiting target users.

You can have sprite with multiple sheets (this way you can have smaller sheets instead of one big sheet). Here’s quote from documentation.

Multiple image sheets

The example below shows how to use multiple unique image sheets for a single sprite object. This is achieved by adding a sheet parameter to each sequence declaration, specifying which image sheet it should pull its frames from.

– 1st image sheet local sheetData1 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 } local sheet1 = graphics.newImageSheet( “mySheet1.png”, sheetData1 ) – 2nd image sheet local sheetData2 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 } local sheet2 = graphics.newImageSheet( “mySheet2.png”, sheetData2 ) – In your sequences, add the parameter ‘sheet=’ referencing which image sheet the sequence should use local sequenceData = { { name=“seq1”, sheet=sheet1, start=1, count=6, time=220, loopCount=0 }, { name=“seq2”, sheet=sheet2, start=1, count=6, time=220, loopCount=0 } } local myAnimation = display.newSprite( sheet1, sequenceData ) myAnimation.x = display.contentWidth/2 ; myAnimation.y = display.contentHeight/2 myAnimation:play() – After a short time, swap the sequence to ‘seq2’ which uses the second image sheet local function swapSheet() myAnimation:setSequence( “seq2” ) myAnimation:play() end timer.performWithDelay( 2000, swapSheet )  

Woah, 2800? That’s too big, you won’t run this on any mobile device.

That because you never passed fallingEnemySequence to newSprite. Second parameter for newSprite is table containing tables of sequences. So you must wrap walikingEnemySequence and fallingEnemySequence in one table and then pass it to function.

Thats because Im working with huge files now im designing it, and I will scale them down once the project is finished, just so I can edit them more easily.

Is this bad?

(Also, which sizes do you reccommend? Thanks for any help you can give)

That solved it! Thanks a lot!

1024 px (width or height) is considered max generally. Newer devices can handle even up to 2048px but you are limiting target users.

You can have sprite with multiple sheets (this way you can have smaller sheets instead of one big sheet). Here’s quote from documentation.

Multiple image sheets

The example below shows how to use multiple unique image sheets for a single sprite object. This is achieved by adding a sheet parameter to each sequence declaration, specifying which image sheet it should pull its frames from.

– 1st image sheet local sheetData1 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 } local sheet1 = graphics.newImageSheet( “mySheet1.png”, sheetData1 ) – 2nd image sheet local sheetData2 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 } local sheet2 = graphics.newImageSheet( “mySheet2.png”, sheetData2 ) – In your sequences, add the parameter ‘sheet=’ referencing which image sheet the sequence should use local sequenceData = { { name=“seq1”, sheet=sheet1, start=1, count=6, time=220, loopCount=0 }, { name=“seq2”, sheet=sheet2, start=1, count=6, time=220, loopCount=0 } } local myAnimation = display.newSprite( sheet1, sequenceData ) myAnimation.x = display.contentWidth/2 ; myAnimation.y = display.contentHeight/2 myAnimation:play() – After a short time, swap the sequence to ‘seq2’ which uses the second image sheet local function swapSheet() myAnimation:setSequence( “seq2” ) myAnimation:play() end timer.performWithDelay( 2000, swapSheet )