How do I spawn object between 2 images ?

0 favourites
  • 4 posts
From the Asset Store
500 monsters and creatures images for card games - Set 1
  • Let's say that the question mark is image1 and the exclamation mark is image2.

    I need to spawn an object between those 2 images. Any ideas ?

  • Ok, I'll call "A" the 1st image and "B" the 2nd one.

    If the images will be always on the same place you can just create the object at the X and Y that is between those images.

    If the images change places try this;

    Create object at

    x = A.x < B.x ? A.x + (B.x - A.x)/2 : B.x + (A.x - B.x)/2

    y = A.y < B.y ? A.y + (B.y - A.y)/2 : B.y + (A.y - B.y)/2

    What this is doing is:

    (A.x < B.x ?) > Is A.x smaller than B.x? In other words is image A on the left side of image B?

    If it is then X will be the part of the code between the "?" and the ":"

    So "x = (A.x + (B.x - A.x)/2)" Which is the same distance from the origin as the image A plus half the distance between A and B.

    If it is not then X will be the part of the code after the ":"

    So "X= B.x + (A.x - B.x)/2" Which is the same thing as before but considering B is on the left side of A

    The code for Y is exactly the same.

    Of course this codes will create the image always in the exact center between images A or B. To create objects anywhere between the A and B the code should be different.

    I'm not sure if this is the best way to do it, but it's how I would do it. Hope it helps

  • You could also do:

    X = (A.x+B.x)/2

    Y = (A.y+B.y)/2

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try this tutorial link below. Many tutorials here for you to learn ... 7YPza?dl=0

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