Set Object1.ImagePoint to Object2.ImagePoint

0 favourites
  • 13 posts
From the Asset Store
The collection includes pre-categorized selections that can be the definitive tone setting backdrop to gameplay.
  • I'm attempting to create a pseudo-3D box.

    • Two sprites make up the top and bottom of the box - 1 on the "Floor" layer, and 1 on the "Top" layer.
    • Pending further adjustments, the paralax for Top is 75, 75, and Floor is 100, 100.
    • All sprites have five image points - origin point is at center while the other four are set to each square's corners.
    • The Sprite BoxBottom has the Solid behavior.
    • The player-controlled sprite, Player, has the 8 Direction, Scroll To, and Bound To Layout behaviors.
    • Layout size is 500, 500 with a window size of 250, 250.
    • With the exception of TopBox sprite, all sprites are currently on the "Floor" layer.

    The viewpoint is while looking top-down (think virtually all the PokeMon games, particularly where the buildings appear 3D as the Trainer moves about town). The lowdown of my goal is to connect the two BoxSide sprites to their respective corners of the BoxTop and BoxBottom sprites. With help of the paralax feature, the BoxTop will move at a different rate than BoxBottom, and the BoxSide sprites will redraw accordingly, creating a simulated 3D effect relative the perspective of the Player sprite as it moves around.

    For instance, if Player is standing to the immediate left of the Box, you will barely be able to see the left side. But the further away Player moves to the left, the more the perspective will shift, allowing the left side of the box to be seen. Move to another position around the Box and you'll see a different side of it.

    Ultimately, what I'm striving to do is use the image points as anchors at every tick. But I'm not seeing where I can reference one image point of one sprite to that of another sprite's image point. I see the Set Position To events/actions, but not specifically for image points.

    My BIG question is if it's even possible to make an image interact between two layers at the same time?

    Here's the .capx file at present... https://www.sugarsync.com/pf/D6025908_4317202_6518506

    Here is an illustration to (hopefully) make clear(er) what I'm trying to accomplish. The graphics are "pixelated" (easier for me to draw), but it's the color scheme that matters, as that's what I have set up in the .capx above.

    https://www.sugarsync.com/pf/D6025908_4317202_6519509

  • Yeah you can make images interact between layers (e.g. collisions and such), but with parallax you get some weird effects... I'm not sure exactly what the math is behind it but I think it stretches/shrinks the x,y plane. Spawning something from a sprite in a normal layer into a parallax layer can cause the spawned object to appear quite a distance away from the original's image point.

    I'm sure you could account for it with some math. A good start would be to use expressions in the expressions panel where you can use sprite.imagepointX(n) and such to reference image points on a sprite and then try some constant multiplier to counteract the effects of the parallax. You can probably circumvent parallax entirely too, that actually might make some of the math a bit easier.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Phyvo - LOL Math, in general, I get. Math via C2 is something else at the moment. At least as far as making happen what I want to happen...

    How would I access Object 1's image point to be set to Object 2's image point?

  • To put sprite1's image point on top of sprite 2's image point (both non-origin) by setting sprite1's position you'd do this:

    sprite 1 set position -

    X: sprite2.imagepointX(q)-(sprite1.imagepointX(r)-sprite1.X)

    Y: sprite2.imagepointY(q)-(sprite1.imagepointY(r)-sprite1.Y)

    I haven't tested that one but I think I got the signs right (it's kinda late for me, zzz). Last time I was faced with this problem I did this which is a little more flashy:

    sprite1 set position -

    X: sprite2.imagepointX(q) y: sprite2.imagepointY(q)

    rotate sprite1 180 degrees

    sprite1 set position - X: sprite1.imagepointX(r) y: sprite1.imagepointY(r)

    rotate sprite1 180 degrees

  • Phyvo - I'll give it a go. Thank you!

  • For clarification, I added a link to an image that better describes what I'm after. Check my second link in the original post.

  • Check out what I did to create a fake 3D box in this thread

    scirra.com/forum/topic62057.html

  • justifun - I'm going over your program and it's blowing my mind. VERY awesome. Not what I have in mind, but it's still VERY awesome! I hope to have the insight to do this straight outta my head in due time.

  • Phyvo - Okay, can you walk me through this? What's this telling C2 to do?

    Particularly the parts I have underlined.

    X: sprite2.imagepointX(q)-(sprite1.imagepointX(r)-sprite1.X)

    Y: sprite2.imagepointY(q)-(sprite1.imagepointY(r)-sprite1.Y)

  • A refined question to my original post:

    Is it possible individually place a sprite according multiple image points on the same sprite? Essentially redrawing/resizing/reshaping the sprite in relation to ANOTHER sprite's image points??

    Here is an updated .capx of what I have now...

    https://www.sugarsync.com/pf/D6025908_4317202_6510878

  • sprite1.X is the absolute X coordinate of sprite1's origin point. imagepointX similarly gives the absolute X coordinate of sprite1's image point relative to Construct's coordinate system (the top left corner). So subtracting the two gives us the difference or relative position of sprite1's imagepoint to sprite1's origin point. This is important because with the Set Position action we are forced to figure out where the sprite's *origin* has to be in order for it's image point to be in the correct place.

    For example, if we have a sprite with origin (1,2) and imagepointXY (3,2) (which means relative difference of (2,0) which you want to move to sprite2's point (5,6) this is how the expression math works out:

    5 - (3 - 1) = 5 - 2 = 3

    6 - (2 - 2) = 6 - 0 = 6

    Notice how in the parentheses we got the relative diffence between sprite1's origin and it's image point. The object's new origin point is (3,6), placing the image point (2,0) from that at (5,6) absolutely.

    If it helps my #1 method for figuring out how exactly what some number means or what something does is to make a quick blank project with a sprite or two and a text object set to any/all values I'm interested in and just muck around until I understand what's going on.

    In answer to your second question, yes it is possible but the math is more work than what I just did. You'll have to use more expression variables like sprite.Height and sprite.Width and resize things. If I have time I might be able to look at your capx later and advise you further but I don't know if I can.

  • Hello, I was searching how to do something quite similar to this.

    (Here's my post scirra.com/FORUM/topic65335_post400758.html

    If you ever figure out how, let me know!

  • Looks like has a better solution than anything I've come up with. C2 doesn't support what I had in mind...at least not yet. What I was trying to do requires the ability to warp shapes (not supported) by way of keeping image points of the same sprite attached to independently moving coordinates (also not supported).

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