How do I get relative screen coordinates?

Get help using Construct 2

Post » Thu Aug 27, 2015 8:11 pm

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
B
3
Posts: 2
Reputation: 179

Post » Thu Aug 27, 2015 11:37 pm

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
Stuff I'm working on:



http://www.jamdonut.com
B
13
S
3
Posts: 88
Reputation: 1,025

Post » Fri Aug 28, 2015 1:43 pm

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.
B
3
Posts: 2
Reputation: 179

Post » Fri Aug 28, 2015 4:46 pm

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.
Stuff I'm working on:



http://www.jamdonut.com
B
13
S
3
Posts: 88
Reputation: 1,025


Return to How do I....?

Who is online

Users browsing this forum: richcoz81 and 39 guests