How do I attach a sprite to another in a specific way?

0 favourites
From the Asset Store
Pixel Sprites ala ReactorCore - Builder Hardware - Large pack of sprites!
  • So I have a player sprite that has four additional points as well of the origin point. I want it to collect the other sprites in any of the four points (but not the origin) while also not having them overlap once that point has been taken. Any tips? Would be greatly appreciated!

  • There are a few options:

    1. Create an instance variable - AttachmentPoint=1. Use it to identify which image point to attach Sprite2 to, and increment it by +1

    2. If attaching with hierarchy you can simply check the number of children on the parent sprite.

    3. You can loop through all 4 image points and check if any of them is not overlapping Sprite2. Use "System Is overlapping point" condition.

  • There are a few options:

    1. Create an instance variable - AttachmentPoint=1. Use it to identify which image point to attach Sprite2 to, and increment it by +1

    2. If attaching with hierarchy you can simply check the number of children on the parent sprite.

    3. You can loop through all 4 image points and check if any of them is not overlapping Sprite2. Use "System Is overlapping point" condition.

    Right, I should have said this before: I've just started dabbling in Construct, but I think Number 1 seems simple... I feel like I might be missing some context: how do you identify the points with an instance variable? Is that where the Event Sheet comes into play?

  • Yes, your event may look something like this:

    Origin image point has index 0. Image points 1-4 are for attaching instances of Sprite2.

  • Yes, your event may look something like this:

    Origin image point has index 0. Image points 1-4 are for attaching instances of Sprite2.

    Nice!

    First point seems to work. But now having done this in an example project, all instances of Sprite 2 seem to point to the same point.

    Not what I was hoping for... Proximity to the points was the thing I was hoping to attract Sprite 2 to Sprite 1, so that by proxy each one would attach to each point. Could it be because I have all my versions of Sprite 2 in the same family and am referencing the family instead? Or is there something more?

  • > Yes, your event may look something like this:

    >

    >

    >

    >

    > Origin image point has index 0. Image points 1-4 are for attaching instances of Sprite2.

    Nice!

    First point seems to work. But now having done this in an example project, all instances of Sprite 2 seem to point to the same point.

    Not what I was hoping for... Proximity to the points was the thing I was hoping to attract Sprite 2 to Sprite 1, so that by proxy each one would attach to each point. Could it be because I have all my versions of Sprite 2 in the same family and am referencing the family instead? Or is there something more?

    Maybe I'm complicating things a little lol

    My idea was to have an instance of Sprite 2 attach to whichever of the 4 points Sprite 1 has nearest it without the other instances of Sprite 2 taking its place. Mind you, I also have the instances of Sprite 2 in a family, and I think I made it harder for myself in doing that, but I'm yet not sure.

  • I should also specify that the points themselves shouldn't be in any specific order, just whichever is closest to Sprite 2 instance.

    You should've mentioned this from the beginning.

    The easiest solution would probably be attaching 4 invisible "Anchor" sprites to these image points - you can do this manually in layout editor, add them as children to the hierarchy.

    Then you can pick the nearest Anchor sprite and replace it with Sprite2:

    Sprite1 On collision with Sprite2
    Sprite1 Pick all children Anchor
    Anchor pick nearest to (Sprite2.x, Sprite2.y)
    ... Sprite2 set position to Anchor
    ... Sprite1 add child Sprite2
    ... Anchor destroy
    

    Alternatively, if you want to do this with image points, you will have to loop through all image points, check which ones are unoccupied, and which one is the nearest to Sprite1 - the code for this will be pretty complicated.

  • Alternatively, if you want to do this with image points, you will have to loop through all image points, check which ones are unoccupied, and which one is the nearest to Sprite1 - the code for this will be pretty complicated.

    Based on my example off of what you said, I think the latter may be the best and more thorough option. I think it gives room for the second part to this as well, which you already gave me the idea on how to solve for with the former example.

    In any case, I must have done something wrong, because some weirdness is going on where the other instances aren't occupying any other anchors.

  • Please post a screenshot of your code or the project file.

  • Please post a screenshot of your code or the project file.

    Actually, *whew...* I got it to work! Thanks so much!

    Now the idea might just be to create more anchors for the Sprite 2s that are connected to Sprite 1, again such that they don't overlap. Thankfully, I think I might just know how to do this thanks to you!

  • My idea has gone bust. Though the initial plan worked, the added complication, well... complicated things.

    I want to know how to add additional instances on anchor points of Sprite 2 attached to Sprite 1 without it jumping all over the place in confusion with itself.

    I don't know how else to explain it, other than that the resulting shape should be bigger. There's also the added idea of pressing space to immediately get rid of the sprite 2 that was just collected, making the overall shape one less than it was. That part I'm almost certain I have down, but angles are weird, too. I hope to reject the piece and it to bullet to the direction from whence it came. That seems like its own post, honestly, but do let me know.

  • An image illustrating what you’re after often helps if you can’t describe it enough to get the idea across.

    I get that you want to be able to attach multiple instances to each point now but you probably need to be more specific about what you want to happen when there are multiple on one point. Should they stack? Should they all not overlap but be close to the point, like in a circle? Or since you said bigger maybe you want them to overlap and scale up based on how many are attached?

    As to the statements about confusion and weird with how your attempts are running I’d recommend sharing a c3p or a screenshot of your events. Typically there is no way to debug things based on descriptions otherwise. But if you meant them as just vents in frustration I can understand that too.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I just realized that the YouTube link isn't working for me for some reason.

    Anyway, maybe this can help illustrate what I mean.

  • Screenshots will be better, I think.

    What I have is basically like a top-down POV of the picture above, but the green one on the top right hovers with the rest of the form, and no other instances will collect.

    So Sprite 1 attaches to Sprite 2 at the anchor points like I wanted.

    What I want is for each Sprite 2 that's attached to then have anchors to attach to other Sprite 2s, but only when attached to Sprite 1. I'm thinking heirarchy and having children of Sprite 1 be Sprite 2 might solve the problem of in which order, but when I press Space I also want the Sprite 2s to shoot out and remake-available the anchors once present.

    The code so far is as follows:

    But I think I messed up towards the end with the Sprite2Anchors somehow. Is there any way I can keep the other ones attachable as well, such that the attached Sprite 2s can keep their positions?

  • What I want is for each Sprite 2 that's attached to then have anchors to attach to other Sprite 2s, but only when attached to Sprite 1. I'm thinking heirarchy and having children of Sprite 1 be Sprite 2 might solve the problem of in which order, but when I press Space I also want the Sprite 2s to shoot out and remake-available the anchors once present.

    Can you draw a picture, showing sprites before attaching, after attaching, after shooting-out, and different combinations of them? How long can these chains get?

    If you need to re-use the anchor points, then don't destroy them. Instead use a instance variable, for example "occupied". When attaching a new sprite, pick nearest anchor with occupied=0, change it to 1. After detaching change it back to 0.

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