Getting specific x values

Get help using Construct 2

Post » Wed Dec 09, 2015 8:22 am

Hey everyone.

I've been trying to figure out how to get the x position of an object from a specific location.

So for example, you have a sprite that has been spawned at x=300 y=300

How would you get the x value of where the sprite ends to the right.

What I have been doing is creating a variable that holds the sprite's width then adding its x position to the width which then equals the x position on the far right of the sprite.

Is there an easier alternative to this?

Thanks.
B
18
S
2
Posts: 48
Reputation: 896

Post » Wed Dec 09, 2015 9:07 am

Ok, its easy.
When you spawn or create object at x:300 y:300 u creating your object and this obiect Origin (image point) is in this point (x:300, y:300).

In most of cases Origin pooint is in the middle of obiect, so its right end will be: createX + obiect.width/2

But if u change origin position it can by more tricky but construct is very helpfull:
Just use obiect.BBoxRight

You can check it on: https://www.scirra.com/manual/133/common-expressions
B
22
S
3
Posts: 74
Reputation: 1,515

Post » Wed Dec 09, 2015 9:08 am

I might of misunderstood your question but depending on the origin point

far right x=sprite.x+sprite.width (origin point far left)
far right x=sprite.x+sprite.width/2 (origin point centered)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Wed Dec 09, 2015 11:05 am

I guess I would go for sprite.bboxleft for the left side and sprite.bboxright for the right side..
That would even work if the sprite has a different shape and is rotated..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Dec 09, 2015 3:15 pm

@hobibit @RamPackWobble @LittleStain

Thanks guys! Managed it!

It was for the random terrain generation similar to kingdom.

Here is the Capx if you ever need something like it

https://onedrive.live.com/redir?resid=E ... ile%2ccapx
B
18
S
2
Posts: 48
Reputation: 896


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests