Destroy one instance of a sprite created at start

  • I've beat my head against this for a couple days, and have read a lot of the posts on here about dealing with instances through UID's, select n'th, etc.

    Here is a .capx of what I am attempting,

    http://dl.dropbox.com/u/30187917/instance_on_creation.capx

    I want to create enemies at specific locations, the enemies are represented by the same sprite, and the HP for each enemy is stored in an array. I use the array to populate 2 values, a maximum and minimum HP for each enemy location. When a minimum HP variable reaches 0 I want the enemy at that location to be destroyed. My problem is, regardless of how I set this up, it's very difficult for me to specifically (and elegantly) assign which instance of the sprite gets destroyed.

    Any suggestions would be greatly appreciated!

  • first, you have four sprite instances - one that is on the right side is your Sprite.Instance=0, top left is Sprite.Instance=1, midle left is Sprite.Instance=2 and bottom left is Sprite.Instance=3. Second, when enemyhp1_hpMin=0 it will destroy Sprite.Instance=0 - right Sprite, and number of instance will change so the second sprite (former Sprite.Instance=1) will be Sprite.Instance=0, and it will be destroyed, and third sprite will become Sprite.Instance=0 et cetera.

    Use private variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • first, you have four sprite instances - one that is on the right side is your Sprite.Instance=0, top left is Sprite.Instance=1, midle left is Sprite.Instance=2 and bottom left is Sprite.Instance=3. Second, when enemyhp1_hpMin=0 it will destroy Sprite.Instance=0 - right Sprite, and number of instance will change so the second sprite (former Sprite.Instance=1) will be Sprite.Instance=0, and it will be destroyed, and third sprite will become Sprite.Instance=0 et cetera.

    Use private variable.

    Thanks for getting back to me! Your point about the sprite instances makes sense. I'll try using an instance variable, and if I get it working I'll post my results. Thanks again man, very informative :)

  • More commented picking for you in capx

    Glorious! This makes so much more sense then what I was attempting, thank you so much!

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