8
« on: 2011-03-21, 08:53:41 AM »
In response to what I think SnapToGround does, I have made these conclusions based on my reading of the documentation and the forums, but I could be dead wrong.
It is a method that is implemented to bring the player sprite all the way to the "ground", which is defined as the solid tile(s) the player sprite lands on. It is declared with other methods such as ReactToSolid and must come immediately after react to solid.
There is a threshold for the SnapToGround method to activate defined in pixels. Once it detects that the player is close enough it alters the y velocity of the player to make sure it does not stop above or below the solid tile and will always reach the same y position relative to the tile.
The method can also be used as a test, since it returns true when it is activated. In my game the test occurs in a place where it must return true for the jump to be possible. Whether it is the SnapToGround method, or the other methods (I have used Blocked, and IsAgainstTile successfuly).
This exercise is merely academic, since the other two methods work without fail. I expect that the player should be "Snapping to the ground" each time it reaches the threshold. It should return true in my "OnLanding" test each time where I have implemented it as a test. It seems to be that most of the time it is doing that, but for reasons I don't understand, sometimes it does not. This makes it so the IsJumping parameter does not get reset and subsequently malfunctions preventing the player from jumping.
The inputs are the same. Press left, or right, and jump at the same time. Do this about 20 times and one of those times will probably result in a failure.
I also expect that the threshold would only need to be 1 pixel, but it requires 11 or 12 before it works. I am unsure of what it uses as a reference. I think would be the same thing the other methods use, but it something seems to be offsetting it. Perhaps there is something else wrong that I am not aware of.
As a precaution I did check the sprite's frameset. I thought maybe that had something to do with it. I found that all of them have a y offset of 5 except for a couple of frames. In the project you have been sent you'll see this inconsistency. I fixed that and it didn't fix the problem so it doesn't seem to be that.