Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
HittestPoint Issue — Gideros Forum

HittestPoint Issue

mertocanmertocan Member
edited April 2012 in General questions
In my game , the stones are sent and if it hits the bird , bird dies , stone child is removed and when bird is out of screen , the bird child is removed. However, sometimes stone doesnt hit the bird but stone is being removed and after few seconds game gives eror and says "The supplied Sprite must be a child of the caller.stack traceback:". There isnt bird and game tries to remove bird. It is complicated. I have been trying to work out that problem for 4 hours. Help please :)

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited April 2012
    sorry, but without some code I'm afraid it's hard to guess what an issue is there.
    At least try to explain how are you implementing bird moving, stone throwing and collision detection.
  • It is hard to explain but i will try :) There is a bird class and there are mouse events in bird class. Also there is a slingshot in the game. If the user touches the slingshot , a stone is created(in bird class) . All of these happens in the bird class. And also i have stone class but it is just for moves of stone. In the bird class i can use self but i cant use self for stones in the bird class. Beacause of that , if user touches the slingshot 2 times. 2 stones are created but previous one cant shot the bird.

    if self:hitTestPoint(stone:getx(),stone:gety())... What can i use to control all of this stones?
  • ar2rsawseenar2rsawseen Maintainer
    Ok, if I understand correctly

    you are using self:hitTestPoint for collision detection between bird and stone?

    Problem is, that well, you actually use only 1 pixel from stone for collision detection, not all stone perimeter.

    Do you use physics in your class? Is bird a box2d object?
  • i just use gravity.Yes it is box2d object.
  • ups sorry it isnt box2d object
  • ar2rsawseenar2rsawseen Maintainer
    edited April 2012
    too bad, it would be possible to use box2d collision detection to handle this.
    now you'd need to implement your own collision detection depending on shapes of your objects.

    Most basic would be to use square area surrounding object and hitTestPoint method.
    if self:hitTestPoint(stone:getx(),stone:gety()) or self:hitTestPoint(stone:getx() + stone:getWidth(),stone:gety()) or self:hitTestPoint(stone:getx() + stone:getWidth(),stone:gety()+stone:getHeight()) or self:hitTestPoint(stone:getx(),stone:gety()+stone:getHeight())
    This example should work, if you are using (0;0) as anchor point.
  • okay i will use it but i will try to learn box2d objects from http://appcodingeasy.com/Gideros-Mobile it would be better if i use box2d thank you so much
Sign In or Register to comment.