Author Topic: Issue with counting frames too fast  (Read 8434 times)

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Trying out different methods
« Reply #15 on: 2011-03-21, 06:32:38 AM »
I was able to get bluemonkmn's code "Against Tile" to work nicely, but am still not able to get the SnapToGround method working consistently. I have uploaded my project if you would like to check it out. The offset must be set at at least 12 before there is a result.

In the project the character will not jump unless the ground is detected using the rule called "OnLanding". You should be able to get it to fail when you turn and jump (while on the ground) simultaneously, but not every time.

Once again I'm reading the forums when I can't look at the project.  Can you tell me exactly what you expect SnapToGround should be doing, and what it *is* doing (just based on your observations)?  You're not expecting it to prevent you from jumping are you?  That's not what it was designd for (although if you pick a significantly high threshhold, it probably could).  What velocity are you using for jumping?  What maximum velocity do you use for horizontal movement?  Anything else I should know about your parameters related to movement in understanding how you expect SnapToGround to work?

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Issue with counting frames too fast
« Reply #16 on: 2011-03-21, 06:45:07 AM »
Yikes, I really missed those functions.  They could have been useful.  Too bad for me!  :P
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

Wyzemann

  • Regular
  • **
  • Posts: 26
    • View Profile
SnapToGround method and my faulty implementation
« Reply #17 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.


bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Issue with counting frames too fast
« Reply #18 on: 2011-03-21, 04:36:43 PM »
OK, I may understand the confusion here.  I didn't realize (remember) that the function could also be used as a test.  If that is the part that is not working as you expect, then I think I can explain it.  When used as a test, you may have noticed that the documented return value is "returns True if the sprite was snapped to the ground."  I guess this may not be clear, but that doesn't necessarily mean that it will always return true when the player is touching the ground.  It only returns true if the function had to do something to snap the player to the ground.  There are cases (I would have expected more than you're reporting) when the player just hit the ground and ReactToSolid already adjusted the player so that it is hitting the ground so SnapToGround doesn't need to do anything else... then it would return false.

Wyzemann

  • Regular
  • **
  • Posts: 26
    • View Profile
Re: Issue with counting frames too fast
« Reply #19 on: 2011-03-21, 09:32:11 PM »
Sounds like a really bad strategy then. I'll stick with IsAgainstTile.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Issue with counting frames too fast
« Reply #20 on: 2011-03-22, 05:04:17 AM »
Does Blocked lack something?

Wyzemann

  • Regular
  • **
  • Posts: 26
    • View Profile
Re: Issue with counting frames too fast
« Reply #21 on: 2011-03-22, 07:33:02 AM »
I have extra options with isAgainstTile since I can specify tile categories and relative alignment. I think this could be useful if I were to, for instance, have some tiles on a level where jumping is prohibited. Chances are I will never do that, but I thought, what the heck. I got it working I might as well use it.