Collision of Sprite event

Discussion in 'Questions (Windows Mobile)' started by enonod, Jun 27, 2009.

  1. enonod

    enonod Well-Known Member Licensed User

    My tests seem to suggest that gw.collision is called twice for a collision, presumably once for each sprite. I did not expect this, is it correct please?
     
  2. agraham

    agraham Expert Licensed User

    I modified the Sprite example program to count Collision events and only got one event per collision.
     
  3. enonod

    enonod Well-Known Member Licensed User

    Thank you for your time agraham. I have taken the liberty of attaching my test (I think it is all there). The reason for the count variable to check was because when the collision occured the direction changed from 90 to 270 deg. so I tested.

    There is a single pixel sprite in the top row, the moving sprite hits it and should change by 90 deg, which it did in other tests.

    [Edit] I have slowed the movement down and it appears to trigger when they collide and again when they part??? weird, what have I done?

    [Edit 1] I think? I see it, it looks like it collides every tick if it hasn't moved within one tick, maybe not the whole answer, but a little help needed if it is, to overcome it.
     

    Attached Files:

    Last edited: Jun 27, 2009
  4. agraham

    agraham Expert Licensed User

    I've looked at the code inside the library and yes, if you don't mark either of the sprites involved in the collision for deletion (as the demo does) then in fact the event is called twice - once for each sprite.

    Also a problem is that there is no way of identifying which sprite is Sprite1 or Sprite2. It would have been useful to have a Name or ID property for a Sprite so you could identify individual Sprites when they are involved in collisions. If the broken collision detection is fixed it would be useful to add this at the same time.
     
  5. enonod

    enonod Well-Known Member Licensed User

    Ah thank you agraham. So I may also have been wrong in my final diagnosis that it was firing per tick if still in contact?? The odd thing is that I did a test which stopped the sprite within the collision sub and the counter kept counting, so perhaps there is a combination of things happening.

    I agree the need for naming the sprites, that would be helpful. I don't know if the index can be used, especially if the sprite add order was known.

    Unfortunately, as can be seen from my test, I don't actually want to delete so I will have to work around it, and at least hope it gets changed.

    Thank you for your time.
    [Edit] You say you looked at the code, is this accessible to all?
     
  6. agraham

    agraham Expert Licensed User

    I overlooked the availability of the index . You should be able to use that as the Sprites are added to an ArrayList in the GameWindow so they are indexed in order of adding. You would have to take care of deletions by adjusting your own index list for each deleted Sprite.

    I use .NET Reflector, class browser, analyzer and decompiler for .NET which can display the code in several .NET languages.
     
    Last edited: Jun 27, 2009
  7. enonod

    enonod Well-Known Member Licensed User

    Sorry I asked agraham, a bit beyond me. End of subject.
    How do I bring this matter to the attention of Erel as a request or will he read anyway?
     
  8. agraham

    agraham Expert Licensed User

    You've already posted a bug report about the collision detection. If you have other suggestions then the Wishlist topic is the place for them but I guess he will read this thread anyway.
     
  9. enonod

    enonod Well-Known Member Licensed User

    Thank you as always.
    The bug report is actually about intersection, but of course I don't know about whether there is any connection, I assumed this was entirely separate.
    Noted.
     
  10. enonod

    enonod Well-Known Member Licensed User

    I have been trying to overcome this and skip one of the event triggers by counting two calls before actually doing something with it. I also used a counter in the event sub and printed it to a label only if it reached a certain count. I slowed the action down to one pixel per sec and the result seemed to show that whatever count was used, it was reached, which meant that for a single collision the event was called up to 6 times.
    The only conclusion I could reach, based on agraham's code check that agreed there were two calls, is that if you prevent one of the events or don't actually do something (I don't know what) then the event sub is continually called until...???
    Very weird. Perhaps somebody can try to find out exactly what actually does happen when two sprites collide and they are not marked for delete. After all, it should not be a requirement that every collision must result in deletes and explosions.
    Please can some clever person help out.
    [Edit] Test attached and note that if the count in the collision sub is decreased then the sprite does not overrun the collision point which is on the grid line.
     
    Last edited: Jun 27, 2009
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice