Pick Instance

0 favourites
  • 15 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hey guys & gals,

    Running into an issue with instances. Trying to wrap my head around the use of them, and began to try and make use of them within my project to increase the functionality of some of my mechanics.

    What I have going on is this:

    Player has to collect 5 hearts. On each collision with 1 of 5 hearts the heart becomes invisible and adds a visible heart to the "heart hud" area. This is working great. When I collide with an enemy the last heart collected reappears and the last "hud heart" is supposed to be removed as well. It works for the first 2 hearts, but then gets all crazy when you go beyond 2 or continually engage with an enemy. I have included a link to my .capx file. If anyone could help out and take a look at what I got and let me know if I'm handling this correctly that would be great.

    .capx file

    Link to actual game play issue : facecjf.com/EmoGuy23



  • Could you explain more by getting crazy ?

    BTW , Checking out your capx right now , and I'm not seeing an issue ?

    Also , I'm not liking the way you are picking your instances

  • Thank you for a quick response!

    I apologize for the wrong choice of words. What I meant by "getting crazy" is that the small hud hearts don't re-appear in the correct order of which they where taken away. (or set invisible)

    Is there a better way to pick them? I'm a noob, and try to only ask questions when I truly can't figure it out myself. Which is rare...

    When I think about it more, ironically I feel I'm over thinking it. I should just set an instance variable on the player that denotes the collection of the heart on collision, and a variable on the small heart for display in the hud.. If that makes any sense.

  • I am a noob too so this may be incorrect. My idea would be to create a graphic of all five hearts together and have an animation (just one frame) of each that would display so animation "Zero" would be all grey hearts, then "One Heart" would be the animation with one heart there and so on.

    Then in your events make a simple event to set your heart HUD to the correct animation based on how many hearts (your global heart counting variable, either the large or the small heart, i am not certain) the character currently has.

    System compare variable if numberofhearts = 0

    - set animation to "Zero"

    If this is not what you're looking for the other advice I can offer is create a text object on your HUD layer and every tick set the text to display your variables (say set text to "Hearts: " & yourheartvariable) - this is for easier debugging while testing your game.

  • Oh I see , Seriously I don't like the way you pick your instances ...

    Oh Well , Can't help you right now , I'm too sleepy , I'll give a response tommorow !

  • wretchedshark That's a great and simple solution for the hud. Like I've suspected, I've been over thinking this..

    Thank you for your advise! I forget about viewing text and see what variables are being triggered.

  • Thanks Whiteclaws! I'm looking more into picking. I think I know what you are talking about. goodnight

  • I've made this example for a similar question a few days ago.

    You need to adapt to your own capx but that's a possible implementation.

  • Kyatric Thank you

    I do not understand

    AmmoDisplay : Pick instance with UID int(dicAmmo.Get("Ammo" & Ammo))

    Is that basically calling on the last AmmoDisplay.UID you stored in the dictionary and destroying it?

    I only ask cause I want to understand. I did't think to use a dictionary.


  • You got it right.

    The condition "Pick by UID" does the picking. The actions then does the logic (in that case indeed, destroying the picked instance).

    In the game you want to make, instead of destroying you'll rather want to set the sprite invisible (as in your HUD the number of elements will be fixed and always appearing at the same position, so spawn them on start of layout and use the dictionary to keep the UID of each HUD instance you need to change the state during gameplay.

  • Ah ha! It's all becoming clearer. Thank you for the example!!

  • Oh ! Kyatric did it :D ... Oh well ... Next Time !

  • haha Thanks anyways Whiteclaws. :)

  • I'm digging the dictionary and UID functionality.

    One question:

    Am I able to use a single dictionary to hold multiple object/sprite UID's or is it best to just use a separate dictionary per object?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I figured since Kyatric helped point in the right direction, that I would share how I implemented the use of a dictionary. Perhaps someone will find this useful as I did :)

    I simplified it best I could:

    -Player can collect set number of items statically placed on level by colliding and setting item invisible.

    -HUD shows number of items collected (in animation form)

    -Collide with enemy and last item collected is taken away and set visible AND HUD will take away last collection as well

    Link to file - dl.dropbox.com/u/58760772/itemCollect.capx

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