# Animation freeze in pre update with super pre update

**URL:** <https://phaser.discourse.group/t/animation-freeze-in-pre-update-with-super-pre-update/11696>\
**Category:** Phaser 3\
**Created:** [May 14, 2022, 1:38am UTC](https://phaser.discourse.group/t/animation-freeze-in-pre-update-with-super-pre-update/11696 "2022-05-14T01:38:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sub](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/sub/32/6527_2.png) [@Sub](https://phaser.discourse.group/u/Sub)\
**Post date:** [May 14, 2022, 1:38am UTC](https://phaser.discourse.group/t/animation-freeze-in-pre-update-with-super-pre-update/11696/1 "2022-05-14T01:38:42Z")

</div>

```javascript
import Phaser from 'phaser'

export default class Gob extends Phaser.Physics.Arcade.Sprite 
{
    
    private target: Phaser.Physics.Arcade.Sprite  

    moveItems(object: this, speed: number): void
    {
        object.y += speed;
        if (object.y >= 595){
            object.destroy()
        }
        
    }

    constructor(scene: Phaser.Scene, x: number, y: number, target: Phaser.Physics.Arcade.Sprite )
    {
        
        super(scene, x, y, 'gob')

        this.target = target

        scene.add.existing(this)
        scene.physics.add.existing(this)
        this.setScale(2)
        this.play("gobRun")
        

        const body = this.body as Phaser.Physics.Arcade.Body
        body.setSize(this.width*0.45, this.height*0.7)
        body.setOffset(9, 6)
        body.setBounce(1,1)
        
        
    }

    preUpdate(time, delta) 
    {   
        super.preUpdate(time, delta)

        if(this.y < 300)
        {
            this.moveItems(this, 2.5)
            
        }else if(this.y > 300 && this.y < 550)
        {
            this.moveItems(this, 4)
            this.play("gobBlitz")

        }else if(this.y > 550 && this.y < 589)
        {
            this.moveItems(this, 2)
            this.play("gobBack")
        }else
        {
            this.play("gobRun")
            this.moveItems(this, 2)
        }
        
        

        if(this.x > this.target.x + 3 && this.y < this.target.y && this.y > 0){
            //this.setRotation(-63);
            
            this.x -= 2;
        }
        if(this.x < this.target.x - 3 && this.y < this.target.y && this.y > 0){
            //this.setRotation(63);
            
            this.x += 2;
        }
        
        
    }
    
}

```

Hello Mates  
I have a sprite, member of a group for which i just cant make rolling the animations…  
I use the pre update with super pre update …

This technic had worked for the player sprite but not for the ennemies…

Someone knows why?

Thx for your time and advices!

---

<div class="post-metadata">

**Author:** ![Sub](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/sub/32/6527_2.png) [@Sub](https://phaser.discourse.group/u/Sub)\
**Post date:** [May 14, 2022, 10:49am UTC](https://phaser.discourse.group/t/animation-freeze-in-pre-update-with-super-pre-update/11696/2 "2022-05-14T10:49:04Z")

</div>

After a good night, i feel i have some clues!

The animation is reload from start each time so it looks freezing… I have to find a way to avoid that !

Dont hesitate to help me aniway. :]

Cheers

---

<div class="post-metadata">

**Author:** ![Sub](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/sub/32/6527_2.png) [@Sub](https://phaser.discourse.group/u/Sub)\
**Post date:** [May 14, 2022, 12:18pm UTC](https://phaser.discourse.group/t/animation-freeze-in-pre-update-with-super-pre-update/11696/3 "2022-05-14T12:18:36Z")

</div>

```javascript
import Phaser from 'phaser'

import GobState from '~/consts/GobState';

export default class Gob extends Phaser.Physics.Arcade.Sprite 
{
    
    private target: Phaser.Physics.Arcade.Sprite  

    private gobState = GobState.Running

    moveItems(object: this, speed: number): void
    {
        object.y += speed;
        if (object.y >= 595){
            object.destroy()
        }
    }

    private testGobStates()
    {
        if(this.y > 300 && this.y < 540 && this.gobState === GobState.Running )
        {
            this.gobState = GobState.Blitzing
            this.play('gobBlitz')
        }
        if(this.y > 540 && this.gobState === GobState.Blitzing )
        {
            this.gobState = GobState.Back
            this.play('gobRun')
        }
    }

    constructor(scene: Phaser.Scene, x: number, y: number, target: Phaser.Physics.Arcade.Sprite )
    {
        
        super(scene, x, y, 'gob')

        this.target = target

        scene.add.existing(this)
        scene.physics.add.existing(this)
        this.setScale(2)
        this.play("gobRun")
        
        const body = this.body as Phaser.Physics.Arcade.Body
        body.setSize(this.width*0.45, this.height*0.7)
        body.setOffset(9, 6)
        body.setBounce(1,1)
    }

    preUpdate(time, delta) 
    {   
        super.preUpdate(time, delta)

        this.testGobStates()
        
        switch(this.gobState){

            case GobState.Running:
            {
                this.moveItems(this, 3)
            }
            break
            case GobState.Blitzing:
            {
                this.moveItems(this, 5)
            }
            break
            case GobState.Back:
            {
                this.moveItems(this, 3)
            }
        }   
        

        if(this.x > this.target.x + 3 && this.y < this.target.y && this.y > 0){
            //this.setRotation(-63);
            
            this.x -= 2;
        }
        if(this.x < this.target.x - 3 && this.y < this.target.y && this.y > 0){
            //this.setRotation(63);
            
            this.x += 2;
        }
        
        
    }

    
}

```

Got it like that! :]
