How do I Only get One Object (sprite) to react to my press, instead of all of the same sprite?

Not favoritedFavorited Favorited 0 favourites
  • 15 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • NOTE: I am not a programmer, and not good at this, thank you for your patience in advance.

    I am trying to set up a mobile game, where after clicking one sprite for a couple seconds, a second one falls (from a random location along the X axis). Then, after a couple seconds, another one falls etc. I have a "Func_Squish" function that "squishes" the spr "on Touched" (when I touch it on the screen). However, when the subsequent spr's fall, they all "squish" when I click one of the spr's and I only one want the spr that I touch to do the squishing. I have been trying to get help from Grok for a bunch of my issues, but now, he keeps saying to add a Family (which I did), but then to reuse "set vector y" action, however, a family will not let me do the "set vector Y" on the spr within the family. AT this point, I not only frustrated, but confused.

    Does anyone have any idea how to not have every one of my spr's "squish" when I press just one of them? I would appreciate the help, and trust me, I'll be back. I am functionally dumb, so please be kind of explanatory, if you don't mind. I do not know lingo and other stuff.

    I have attached screenshots, and here is a link to the project file, if that helps.

    https://drive.google.com/file/d/1Dqa0ph_38B6PJWCOlL6SUsr-pYgQ7iBA/view?usp=sharing

  • There's a few things:

    For some reason that I don't understand, "Touch - Is touching Fam_spr" picks all the spr's rather than just the one that being touched.

    To solve that, replace Fam_spr with spr

    But that still doesn't work because the function resets the picking list and will pick all spr's again. To solve that, edit the function and enable "copy picked" - this will copy the list of spr's picked in the event that calls the function and pass it to the function.

    Also, you don't need "Every tick" in that function.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Instead of a function, I recommend using a custom action. It works almost identical to a function but the function doesn't pick an instance, so it just applies to all of them. The custom action only applies to whatever instance was picked. In your case, the Fam_Ducks which are being touched.

    Btw you also don't need every tick inside a function. It does nothing.

  • There's a few things:

    For some reason that I don't understand, "Touch - Is touching Fam_spr" picks all the spr's rather than just the one that being touched.

    To solve that, replace Fam_spr with spr

    But that still doesn't work because the function resets the picking list and will pick all spr's again. To solve that, edit the function and enable "copy picked" - this will copy the list of spr's picked in the event that calls the function and pass it to the function.

    Also, you don't need "Every tick" in that function.

    Let me start with your last tip first: you say I don't need "Every Tick" in the function... so what do I place in that spot? I need the System Action, and I need something in there. Does this function not need to take place every tick? And if not... WHEN?

    NOTE: the reason I have the System-> Every TIck is my local variable = "SquishFactor" which sets the initial state of the spr. When the spr falls, its initial state is "SquishFactor=0", but then when I press the spr, I wanted a randomness to the "squishyness" of the spr.

  • "On any touch" only triggers when you start the touch

    Then Func_Squish is only called if Touch Is touching Fam_spr

    So the code in the function only runs once per touch

    "Every tick" does nothing - you can just delete it

    Your squishFactor will still be randomised every time the function is called

    Note that you NEVER actually need "Every tick"! If the trigger/condition column is empty, the actions will always run every tick.

    Events can either be "Conditions" which are checked every tick or "Triggers" which only fire when something happens.

    More details here:

    construct.net/en/make-games/manuals/construct-3/project-primitives/events/how-events-work

  • "On any touch" only triggers when you start the touch

    Then Func_Squish is only called if Touch Is touching Fam_spr

    So the code in the function only runs once per touch

    "Every tick" does nothing - you can just delete it

    Your squishFactor will still be randomised every time the function is called

    Note that you NEVER actually need "Every tick"! If the trigger/condition column is empty, the actions will always run every tick.

    Events can either be "Conditions" which are checked every tick or "Triggers" which only fire when something happens.

    More details here:

    https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/events/how-events-work

    Oh! Ok, I deleted the "Every Tick" under the Function and the "localNumber=SquishFactor"; I thought I always had to have some kind of structure to every action; I thought they were always supposed to be formed like

    affectThisThing->whenThisHappens->byDoingThisThing. I don't really understand, but I think I do a little bit. Thank you.

  • Instead of a function, I recommend using a custom action. It works almost identical to a function but the function doesn't pick an instance, so it just applies to all of them. The custom action only applies to whatever instance was picked. In your case, the Fam_Ducks which are being touched.

    Btw you also don't need every tick inside a function. It does nothing.

    When you say custom action, I set one up, but I cannot set my squishFactors, nor my OriginalWidths / OriginalHeights. How would I set up a Tween, and "squishy" thing using a custom action? Do you know of any tutorial that shows this?

  • affectThisThing->whenThisHappens->byDoingThisThing. I don't really understand, but I think I do a little bit. Thank you.

    You just need to remember that, if an event has no conditions or triggers, it will run every tick - it's the "tick" that effectively triggers the event

  • I'm getting sidetracked. Apologies. I will wrangle this back to my original question: I have a green square (spr) that is the main sprite image for my game. I want one "spr" to fall after every 10ish seconds, and each time I press on one spr, I want only that one spr to squish. How would I set up the spr's to be affected individually on screen, when they will all share most of the same attributes. There could be up to 50 spr's on screen, and I don't want to make 50 different sprite references using the same image graphic. I know there is a way to do this, I just do not know how.

  • You are conceptually doing the right thing, but you missed a couple of key ideas when working with families and functions.

    Families

    1. When you use a family to pick instances in a condition block, you then need to use the family in the action block for the picking to work as you expect. If you directly use the object type that is part of the family in the action block, then the picking that took place in the condition block will be lost.
    2. If you want object types to share behaviours, effects or instance variables through a family, you have to add those to the family itself. This connects with the last point, because if the behaviour, effect or instance variable you want to use has not been added to the family, it won't be available to actions for the family.

    construct.net/en/make-games/manuals/construct-3/project-primitives/objects/families

    Functions

    You can use the Copy Picked option so that the picked instances in the body of a function will be the same as the picked instances in the action block that called the function. If you don't use this option when the function executes, the picking is reset.

    In your case this ties up with the first point because the picking done by the On Touched condition was done through a family.

    construct.net/en/make-games/manuals/construct-3/project-primitives/events/functions

    I updated your project so you can compare it against the old one to see what all of that means in practice!

    drive.google.com/file/d/1KdU6BY1cOFQhfmTXYRcza5LlmWTvcGz1/view

    I felt that making those changes was a little bit clunky, so maybe we will fix that in the future.

  • I think the problem is because you set your event like this:

    Touch is touching fam_ducks -> call squishDuck

    and inside squishDuck you use this:

    System every tick -> duck Tween_squish splash stuff

    because the function doesn't pick any duck or fam_ducks, then the action duck Tween_squish applies to ALL DUCKS.

    Do you call function squishDuck somewhere else? If not, then maybe you don't need it, and you can just call the tween action at the touching fam_ducks event. I assume this Tween_squish behavior is from the family and not from the individual duck, if so, you can do this:

    Touch is touching Fam_Ducks -> Fam_ducks Tween_squish actions

    Make sure than you're tweening the Fam_Ducks family and not the duck, because at the event touching Fam_Ducks Construct already picked the member of the family for you to manipulate. If you use duck Tween_squish, it will apply to all the ducks again since your event didn't pick any duck

  • I updated your project so you can compare it against the old one to see what all of that means in practice!

    https://drive.google.com/file/d/1KdU6BY1cOFQhfmTXYRcza5LlmWTvcGz1/view?usp=sharing

    I felt that making those changes was a little bit clunky, so maybe we will fix that in the future.

    HOW DID YOU GET THE SET VECTOR Y AND TWEEN TO SHOW ON THE FAMILY ACTIONS!? I would have done what you did (somewhat), but when I would use the family as a my object, there was no "Set Vector Y/X" available. It is so frustrating! Not to mention "Tween" does not even show up on my family (in MY file, not the one you corrected). What am I doing wrong?

  • When you click on a Family, you are able to add instance variables, behaviours and effects from the Properties bar, which are different to the ones of the object types.

    Having said that, I think there is a subtle bug in there because I couldn't add Tween to the family right away, I had to create a new empty Family, add the Tween behaviour to it and then add the object type.

  • Regardless, man, I did not mean for you to do the whole thing for me, but your corrections have the game doing almost exactly what I need it to. THANK YOU! I have been looking at the edited event sheet (yours) and I can mostly follow what you did, although I think I do have a couple questions with some of the actions. I am trying to read and comprehend the Family and Copy Picked stuff you mentioned in the manual.

  • Now that I have that, how would I go about making spr's bounce off each other? They bounce off the walls, and they bounce when I click them, but when I add a BULLET behavior and enable BOUNCE, it does nothing. I enabled the collisions for the PLATFORM behavior, but I do not know what to add to make them bounce off one another. Google shows nothing but a pong tutorial and some other 10+ years old stuff that I don't know would apply.

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