Jump to content

Stop sprite on diagonal directions


Gyldstrand
 Share

Recommended Posts

I had code just for that thing somewhere. I'll try to find it. And when that thing will be merged https://github.com/pixijs/pixi.js/pull/2237 you'll be able to remove huge number of lines from your code. That is the patch for fixing crop and rotations of texture, you said that crop isnt working right, so im gonna fix it again. That patch contains class GroupD8 which is handling all rotations and reflections in 8 directions.

Link to comment
Share on other sites

Thats some crazy logic going on! Will make maintenance/improvements fun!

Why not simply sum the movement inputs and then get your direction from that? This way an x++ and an x-- (D and A) simply cancel each other out resulting in 0 movement along the x axis.

This will result in 9 states for your sprite, which is far easier to manage than all those conditionals.

Sounds like you'll probably need to keep track of your current state and the last state so that when you hit the idle state (no key presses, or, more accurate, no forces—if you are summing forces then hitting all keys will result in 0 force) you check the last state and play the idle animation related to that last state.

If you only had one idle animation then there would be no need to keep track of the last state.

Link to comment
Share on other sites

Every time I tried one of the simple methods I would get problems when multiple directions are pressed so I started force feeding it code. If I use 1 idle animation with all the idle frames wouldn't I still have to set it in the same spots as the current individual ones and specify the frame start and end? 

I don't really want the directions to cancel each other out cause that causes a lot of random stops in the player movement. 

Also looking for a way to continue an animation cycle through direction changes.

Link to comment
Share on other sites

5 hours ago, Gyldstrand said:

I don't really want the directions to cancel each other out cause that causes a lot of random stops in the player movement. 

I'm not following, why random stops in movement?

The movement is controlled by the keypresses, doesnt really matter if you sum forces after gathering keypresses or stop forces from occurring whilst gathering keypresses. At the end of gathering input your character is in 1 of only 9 possible movement states (4 cardinal directions, 4 diagonal directions and 1 stopped/idle state), it can only ever be in 1 of those states so your animation code becomes simpler—just display the animation associated with the state.

Shame you abandoned the project, on to better/new things hopefully.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...