Pin SpriteA ImgPoint to SpriteB ImgPoint?

0 favourites
  • 9 posts
From the Asset Store
Wall Pin Board is a hyper causal game developed for fun and inspired by YouTube video whose link is given in description
  • Hi! I found a few examples how to pin/move objects to another objects image point like this (both lines work):

    <img src="" border="0" />

    But is it possible to get a list of available image points of the source sprite to attach SpriteB(2) to SpirteA(1) for example? Right now it seems only the target can have a specific Imagepoint. <img src="smileys/smiley5.gif" border="0" align="middle" />

    For now I just tested it with OnClick and move SpriteB to SpriteA but the ideal solution would be if you could drag & drop objects onto the image points of another object and they would "snap" (and rotate held object with right click for example). So you could snap a cube to a triangle on any of their flat sides together - I hope you can understand what I mean. So can you get the source image points somehow to be able to drag and snap them to the target?

    Another alternative would be to click on the source object and then on the image points of the target to attach it there, but you still need to get the image points of the Source sprite to be able to rotate it and attach it to the target properly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Couldn't you compare the distance of the imagepoints of spriteA to the imagepoints of spriteB and then snap to the closest?

  • Like:

    Get SpriteA.ImagePoint.X, SpriteA.ImagePoint.Y

    Get SpriteB.ImagePoint.X, SpriteB.ImagePoint.Y

    (stored in a local/global Variable?)

    If X and Y values are only +/- 10 Pixels apart snap/drop it there and pin it? (need to get the angle for triangles or rotated targets)

    I will try if this works when I am back. Thanks for the hint. :)

  • You could just use a system compare two values event for that.

    You don't have to store anything in a variable.

    system compare values : distance(SpriteA.imagepointx(1),SpriteA.imagepointy(1),SpriteB.imagepointx(1),SpriteB.imagepointy(1)) - is less or equal to - 10

  • Great idea! But this does not work with multiple points and objects, right? You cant add a loop like "for each point on SpriteA compare if near any point in Working area"?

    Let me explain: In the final game you have to select one object with X points (different for different objects) and you can have one or more (!) objects in the working area where you place it which have also the same or different amount of image points. There could be some squares, a triangle and so where the selected object needs to snap on.

    So I need to do "For ImagePointCount loops" for all objects and store them in an array to compare all values against the coords of the currently selected item? Or is there an easier solution.

  • I am trying it with an array now. But I could need a few hints from experienced users.

    The player can select from several parts and rotate/place them at existing parts in the game to build something with it.

    What I have so far (not entirely tested):

    <img src="" border="0" />

    Assuming the added parts work as expected the next thing would be to check if Sprite2 (or the currently selected/dragged item) Image Points are +/- 5 Pixels to any other imagepoint (except origin) and if they are they should snap and place the dragged/selected object.

    When trying to check if the X and Y points are > 5px or < 5px it seems I have to add many new conditions for it. AND or OR don't seem to work in the expressions? <img src="smileys/smiley5.gif" border="0" align="middle" />

    (e.g. in a "for loop" for each array item but if you have a loop as subevent of a loop, how can you select the loopindex from the first one?)

  • Just a quick addition.

    If you want to have "sub-hardpoints" for things like equipment or weapons there is no way to get an ImagePoints name, right? So it would be the best solution to add them as instance variable and put the x,y coords for the points there?

  • I just did something similar like this, its really quite simple.

    For your ship. in the sprite editor add image points all over the ship where things can attach.

    Next lets create a dummy sprite that will show up at wherever these attachment points are while the mouse is held down.

    Mouse Event (On mouse down AND is touching ship addon part: eg: "lasers")

    (Local variable - ShipAttachPoints

    System For Each "Ship" -> Set ShipAttachPoints = Ship.ImagePointCount

    (sub event) - For "y" from 1 to CountAttachPoints -> Create Object "Attachpoint" at Ship.ImagepointX(loopindex), Ship.ImagepointY(loopindex)

    Pin Attachpoint to Ship

    This will create attachpoint objects all over your ship at each imagepoint and pin it so that they follow your ship.

    Next you need to check how far away the selected piece is to the closest ship attach point, and upon mouse release, snap the pieces together and pin the piece to the attachpoint.

    On Mouse Release

    Pick Nearest (attach point) (from attachpoint to mouse position)

    (subevent) compare 2 values (distance(attachpoint.x attachpoint.y, mouse.x, mouse.y) < 10 pixels

    subevent -> set position and angle of ship piece to attachpoint.

    voila. The piece will snap to the closest attachment point when you release the mouse.

  • justifun or anyone else that understands his solution, can you please post a capx for it?


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