Flip Sprite Horizontally On Collide

I need to know how to flip a sprite either on collide or inside of this patrol code… This is what we tried, it says that flipX is not defined…

// custom component controlling enemy patrol movement
export default function patrol(speed = 60, dir = 1) {
	return {
		id: "patrol",
		require: [ "pos", "area", ],
		
    add() {
      this.enemy = this;
      
			this.on("collide", (obj, col) => {
				dir = -dir;
        this.enemy.flipX = !this.enemy.flipX;
			})
		},
		update() {
			this.move(speed * dir, 0)
		}
	}
};

https://dragon-hunt.ellaberrett.repl.co

Never mind, I figured it out!

export default function patrol(speed = 60, dir = 1) {
return {
id: "patrol",
require: [ "pos", "area", ],
add() {
this.on("collide", (obj, col) => {
if (col.isRight()) {
dir = -dir,
          this.flipX(false);
}else if(col.isLeft()) {
          dir = -dir,
            this.flipX(true);
        }
})
},
update() {
this.move(speed * dir, 0)
},
}
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.