Skip to content

Fliping the Character #2725

Answered by eonarheim
cemalgnlts asked this question in Q&A
Aug 2, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

@cemalgnlts Great question!

What you have can work just fine. (If you use latest alpha bits there is a new top level this.graphics.flipHorizontal = true that can be used)

Other approaches we use are pre defining their flipped graphics in the onInitialize

// my actor
onInitialize { 
  const leftIdle = new ex.Animation({...})
  this.graphics.add('left-idle', leftIdle);
 
  const rightIdle = leftIdle.clone();
  rightIdle.flipHorizontal = true;
  this.graphics.add('right-idle', rightIdle);
}

onPreUpdate(engine) {
  this.vel.x = 0;
  
  if(engine.input.keyboard.isHeld(ex.Input.Keys.A)
    || engine.input.keyboard.isHeld(ex.Input.Keys.Left)) {
			
    this.graphics.use('left-idle')
    
    this.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cemalgnlts
Comment options

Answer selected by cemalgnlts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants