How do I pick only one sprite by comparission

  • Hi,

    I'm picking sprite with boo var. boo is set to inform weather sprite is free to pick or not. However sometimes i have more then one sprite free to pick, and picking by comparison picks all of them. I tired fixing this with trigger once, but it doesn't seam to help. Any suggestions welcome. Also, if anyone knows how to do "on picking failed", so I can do another action if there are none sprites to pick that would be ace. Cheers

  • When no sprites are picked at all, an else will trigger (it's actually the only time you want to use else with a picking condition).

    As for you first issue, try adding a condition system: pick Nth instance or pick random instance depending on your need after your conditions.

  • One idea : instead of having a boolean, you could have an instance variable "ID" and a global variable "NumberOfInstancesAvailable". When a new instance is available, ,you attribute the value "NumberOfInstancesAvailable"+1 to the ID and then you add 1 to NumberOfInstancesAvailable.

    When you pick an instance, instead of checking all instances with boolean set to true, you pick the instance which ID is such that ID=NumberOfInstancesAvailable and you substract one to NumberOfInstancesAvailable.

  • I hadn't seen the post of aphrodite. I didn't know these commands, it looks great

  • When no sprites are picked at all, an else will trigger (it's actually the only time you want to use else with a picking condition).

    As for you first issue, try adding a condition system: pick Nth instance or pick random instance depending on your need after your conditions.

    Hi,

    So you're saying that my event should look like more like this: Sprite.BooIsAvaible = 1, Pick Nth instance of the sprite? Will it only pick one instance and move on, or will it pick all nth instances? I'll check that out.

    @conker23 I tried similar approach, but it didn't work. I might look in to it again and try different approach if Aphrodites way won't work.

  • pick Nth imstance will pick the nth instance (1st or 2nd or 3rd or 4th etc...) not multiple instances AFAIK

  • pick Nth imstance will pick the nth instance (1st or 2nd or 3rd or 4th etc...) not multiple instances AFAIK

    Sweet, thx

  • pick Nth imstance will pick the nth instance (1st or 2nd or 3rd or 4th etc...) not multiple instances AFAIK

    Yo, any clue how can I use that nth instance picking without knowing IID? Or get IID of one object from many that have boo set true.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sprite > Boolean=true.

    Pick sprite nth instance 0.

    You now have the sprite where Boolean=true with the lowest IID. Sprite.IID in actions is now the IID of the picked sprite so it's knowable.

  • Sprite > Boolean=true.

    Pick sprite nth instance 0.

    You now have the sprite where Boolean=true with the lowest IID. Sprite.IID in actions is now the IID of the picked sprite so it's knowable.

    Ah man, gotch ya. So it is 0 based index of picked sprites and not of all sprites IID's, correct? And thx. Althought. literaly the moment you wrote your post, I've changed from reusing existing sprite in to destroying and creating them. And it worked. After seeing your post I've fixed the reusing sprites events, and they work too. Interestingly, I don't see any difference in performance between both ways ( thought at first glance I'm leaning towards spawn/destroy option having better fps). I thought from some old topics, that creating objects is more taxing o the framerate. I guess I'll have to check for average fpx.

  • Yes it's always 0 based index of sprites picked by the condition you set, this could be all of a family, all sprites that have a variable set to 0 etc. Not sure what your game does exactly but creating many objects can eventually affect performance.

  • Yes it's always 0 based index of sprites picked by the condition you set, this could be all of a family, all sprites that have a variable set to 0 etc. Not sure what your game does exactly but creating many objects can eventually affect performance.

    I'm creating trails. Sort of infinite runner type of generation. They move from top of the screen to bottom. Idea was, that once they leave the layout they are free to be picked by the pathway generator and be placed again on top of the screen. Alternatively I just create object on top of layout, and destroy once it leaves the layout.

  • Yeah seems like the same thing either way, moving it or destroying and creating it.

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