How do I get relative screen coordinates?

0 favourites
  • 4 posts
From the Asset Store
Is a circular loading screen with code ready to use. No Animation.
  • So, im going to try to explain this.

    im trying to make the width of an object change relative to where it is on the screen (x coordinate).

    i was trying to find some way of getting the relative coordinates based on the distance between the object and my camera sprite that the camera follows, to fix it that way somehow.

    I really cant get this to work, since im not really a coding genious.

    any help is appreciated

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • there is a function called ViewportLeft(Layer) which you can use to calculate the distance.

    E.g.

    Condition: On start of layout

    Action: Object Set Width Self.X - ViewportLeft(Layer)

    This would set the width of the object to the distance between the left of viewport and the objects X

  • Alright, first of, thank you for sparing me so much pain. I think i'm atleast on the right track now.

    So it works like it should now, but i dont want the object to stretch all the way to the edge of the screen. i want it to stretch from 96 to 0 pixels width while going from the very left to the middle of the screen.

    Might need some explanation - i want a wall to appear 3D by adjusting width based on camera X

    so if the thing was at the very left its width was 96 pixels while in the middle it would be 0.

    i tried adding a + 100 / - 100 in an attempt to fix it, but to no success.

    there any way?

    EDIT:

    So i made it work by doing (Self.X + ViewpointLeft(2)) /6 - 70. now the building shifts correctly and stuff.

    but thanks for the support! without the Viewpoint stuff i'd still be punching keyboards now.

    For anyone that might find this useful - the /6 - 70 part can be adjusted freely for different effects (kinda). If you're trying to do anything similar you might find you need to change these numbers a bit.

  • Sorry I wasn't around to follow up, I was putting my latest game on greenlight and it stole my night lol. Looks like you got there in the end, glad I could help.

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