Tricky: Refer position to other sprite

  • Let's say I have a radar on the right of my screen and a map set up on the left, and when I click on the radar on the right, it creates an object in the same position on the left.

    This much I can do using:

    SpriteLeft.X+(Mouse.X-SpriteRight.X)

    SpriteLeft.Y+(Mouse.Y-SpriteRight.Y)

    My question is... what do I do if the item on the right is rotating? I feel like it's something to do with polar, suggesting distance instead of simple X and Y, but what if said item is not always the same size?

    Starting to get rather complicated.

    Here's my attempt. Any help would be appreciated!

    MirrorSpin?

  • It's not tricky when you know The Secret Formula <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://www.dropbox.com/s/r3snun2rxv9og ... .capx?dl=0

  • It's not tricky when you know The Secret Formula <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://www.dropbox.com/s/r3snun2rxv9og ... .capx?dl=0

    Ah, cos and sin... my old nemesis. Thanks for this.

    I imagine it'll be simple to set the scale variable based on the size of the sprite on the left / size on the right.

  • dop2000 I'm afraid I'm making it more tricky.

    It's hard to describe, but the way in which my actual test works is making use of the Paster Plugin. I try to keep my requests for help plugin free, thus the random grid example.

    My version is pasting an image of a sprite that's offscreen and making it rotate purely via the paster (meaning the off-screen sprite isn't actually rotating, but only the paster 'camera' is, not the paster screen).

    Sorry... I know it sounds complicated.

    My previous example, it turns out, didn't express this correctly.

    While the mouse cursor is over the paster screen, a fake mouse cursor appears over the off-screen sprite in the position the mouse is currently hovering over on the paster screen.

    I hope some of this helped explain what I'm trying to do, but I wouldn't be surprised if it just confused you.

    In any case, I've altered the original capx to show what I mean. Now, when you click on the sprite on the right, instead of creating a sprite on the left, it will create a sprite where it thinks the mouse cursor is based on the cos/sin.

    Note that when the sprite on the right ISN'T rotating, clicking on the sprite puts it in the right position, but when you DO spin it, after a short while, the positioning gets further and further away from the mouse position.

    Do you know of a way to ensure that the version of the right utilizes the cos/sin code? Again, I can't just use the mouse position as the real items is off-screen.

    Eeep, sorry...

    Mirror Sorry!!!?

  • If you have the paster plugin, I can make a more direct example of what I'm trying to do.

  • AnD4D , Yes, I have Paster.

  • AnD4D , Yes, I have Paster.

    Updated CAPX?

    Updated Paster Plugin?

    The Paster plugin I use has been updated to allow layer pasting, so I'm not sure it'll be compatible with your one... so I've attached it as well.

    I hope this demonstrates what I'm aiming for. Note it works at the start, but as soon as you start the spinning, it loses track.

    If you activate the scale event at the top of the event sheet, you can see the actual sprite, rather than the screen.

  • In event #2 simply change "-" to "+" in this formula

    a=angle(Paster.X, Paster.Y, mouse.X, Mouse.Y)+Paster.ThisAngle

  • Ah nice, I still need to tweak it a little bit here and there I think, but I'm certainly on the right track. Amazing how simple it is to completely break this setup.

  • dop2000 Sorry to keep bothering you, but I believe this is nearly complete.

    I've added a select box to the project, which is based on:

    Width = SelectionBox.X-Mouse.X

    Height = SelectionBox.Y-Mouse.Y

    Select Box?

    The issue I'm having is again related to the fact that it rotates. Note that when it's not rotating, it works well, and I've set it so that the selection box's origin remains at the location where you click, but I'm unable to set the Width and Height to the X and Y because if the 'camera' rotates 90 degrees, X becomes Y and vice versa.

    I honestly thought this would be an easy experiment, and can't believe how complicated it's become.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • AnD4D

    Not sure if this is what you wanted..

    https://www.dropbox.com/s/nc4etntyw8oz2 ... .capx?dl=0

  • Here's a reference to translate objects from a scaled and rotated grid to a unrotated and unscaled one:

    https://www.dropbox.com/s/xmf1vzc0f7y5u ... .capx?dl=1

    Left click to drag the mario around on the right, and right click to draw a box on the right.

  • AnD4D

    Not sure if this is what you wanted..

    https://www.dropbox.com/s/nc4etntyw8oz2 ... .capx?dl=0

    Hi thanks, but that's not quite what I was aiming for. I did have it similar to this at one point, but it's the opposite to what I'm aiming for.

    The screen (the one that's spinning) should always have a straight selection box, while the actual sprite off-screen can have whatever angle selection as required.

    Here's a reference to translate objects from a scaled and rotated grid to a unrotated and unscaled one:

    https://www.dropbox.com/s/xmf1vzc0f7y5u ... .capx?dl=1

    Left click to drag the mario around on the right, and right click to draw a box on the right.

    The positioning is spot on, but the selection box is the same issue I'm experiencing. It also appears a slightly more complicated method than Dop's. Perhaps I'm missing something, but I wonder if this would translate well to the Paster plugin example I've shared.

  • It’s similar to dop’s. His uses angle and distance instead of xy. For stuff with equations I find it’s faster to start from scratch instead of debugging. Anyways, my goal with the capx was to do the selection box since that wasn’t solved yet in the latest examples from what I could tell. But if mine has the same kind of issue with it I’m at a bit of a loss.

    Do you mean you want the selection box to always be aligned on the grid? Dop may be closer in his example then.

  • It’s similar to dop’s. His uses angle and distance instead of xy. For stuff with equations I find it’s faster to start from scratch instead of debugging. Anyways, my goal with the capx was to do the selection box since that wasn’t solved yet in the latest examples from what I could tell. But if mine has the same kind of issue with it I’m at a bit of a loss.

    Do you mean you want the selection box to always be aligned on the grid? Dop may be closer in his example then.

    Yeah. I'm trying to use paster as a split screen, but want the player to be able to drag a selection box around objects in the second screen. This is done by having a second 'cursor' appear on the off-screen in relation to where the mouse is pointing.

    This was all working fine until I started to wonder whether or not it would be possible to rotate the pasted image. This required the selection box to rotate so that it always appeared straight on the main screen, while it was rotating accordingly on top of the off-screen object.

    Even though nothing is actually rotating, having the paster object rotate before pasting an image creates the illusion that it is spinning (as I'm sure you already know... it being your plugin). I didn't, however, anticipate all the issues that follow in regard to having things rotate in the opposite direction, as well as in the same direction in order to create the illusion that only the pasted sprites are moving.

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