Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthormacco
    • CommentTimeAug 10th 2008
     
    Is there a way to hitTestObject Particles?
    • CommentAuthorRichard
    • CommentTimeAug 10th 2008
     
    Hi Macco

    If you use a DisplayObjectRenderer then each particle is represented by a unique display object and you can do a hitTestObject on it. The display object is the particle's image property so do

    displayObj.hitTestObject( particle.image );

    If you use a PixelRenderer then each particle is represented by a single pixel and you can do a hitTestPoint on the particle's x and y position

    displayObj.hitTestPoint( particle.x, particle.y );

    If you use a BitmapRenderer then you can't do a hitTestObject on the particle. In theory you could create your own hitTest method based on the particle's x and y coordinates, scale, image.width, image.height, etc.
    • CommentAuthorUbuntu
    • CommentTimeJul 16th 2010
     
    I am very confused with the particle hitTestObject and hitTestPoint because I cant find any examples and cant get mine to work. I am using your GravityWells class except the emitter is called gravityemitter and I have a movieclip on the stage with instance Testbox. And the following code doesnt work:

    if(Testbox.hitTestPoint(gravityemitter.particles.x, gravityemitter.particles.y))
    {
    trace('hit');
    }

    What am I doing wrong? btw for the displayobjectrenderer and pixelrenderer is there anything that must be imported for the hitTests to work? And are there any online examples? Other than this, I love your Particle Engine Richard, and I am planning on creating some games with them. -Thank You
    • CommentAuthorRichard
    • CommentTimeJul 24th 2010
     
    Hi

    The particles property is an array. If you want to hittest an individual particle, you need to use one item from the array, not the whole array. i.e.

    if(Testbox.hitTestPoint(gravityemitter.particles[0].x, gravityemitter.particles[0].y))
    {
    trace('hit');
    }
    • CommentAuthorUbuntu
    • CommentTimeJul 28th 2010
     
    Thank u it works fine now.