Count objects

  • Hello, how can i count objects on screen and then work with them?

    i have 4 objects, if they all have sprite animation frame equal to 4, then destroy.

    Thanks

  • Object.count is the number of all instances of this object on the layout.

    Object.pickedCount - number of instances picked by event.

    So, if you want to check if all sprite instances are on animation frame #4, you can do this:

    Sprite animation frame=4
     System compare two values (Sprite.count=Sprite.pickedCount) -> Sprite destroy
    
  • Thanks again man! Its works!

  • And quick question - i have objects closely to each other, if objects collide with bullet then destroy. But sometimes my bullet destroys two nearest objects, how i can fix it?

  • Bullet on collision with Object
     Object pick nearest to (Bullet.X, Bullet.Y) -> Object destroy
    
  • dop2000 - you are my hero! Thanks a lot!

  • One more question:

    I have bullet animation frame same as objects animation frame, how i can do this:

    if objects on screen with animation frame equal to 0, then dont spawn bullet with this animation frame

    Thanks a lot!

  • I don't quite understand. If you need to spawn a bullet only if an object exists with animation frame>0, you can do this:

    Object animation frame not equal 0 -> Spawn bullet

  • Sorry, i have blocks with random frame on start(4 colors), i have bullet with 4 frames(4 colors), if my bullet collision with block - block destroyed and then spawn new bullet with random color(one of four), but i need thats if no block with color "blue"(for example) on screen - dont spawn bullet with color "blue"

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So if there are blocks with colors "red" and "green" on the screen, but no "blue" block, you need to spawn a bullet and set its color to randomly to "red" or "green" (but not "blue"). Is this correct?

    You can do this:

    System Pick random instance of Block 
     -> Create Bullet
     -> set Bullet animation frame to Block.AnimationFrame
    

    The problem with this method is that if you have 9 red blocks and 1 green block on the screen, then there is a 90% chance that your bullet will be red.

    Also, note that if you are doing this inside some parent event (for example "Bullet on collision with Block"), you will need to execute "System-Pick all Block" event first.

  • This is not correct?

    prntscr.com/k2xbj6

  • Seems ok to me. You don't need "Pick all" condition here.

  • Oh, cool! Its works, but my first bullet generated on start layout may not coincide with block colors

  • Nope, not work, still generates random color :( Maybe i need to add "pick all" here?

    prntscr.com/k2xxj6

  • I don't understand what are you trying to do.

    In your last screenshot when the ball hits a block, you are spawning particles the same color as the block (which was hit). What this has to do with your previous question about bullets?

    You should probably post your entire project and explain how exactly it's supposed to work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)