 Thread: What is the formula to get the x cordinate on an object on a layer with a coefficient

1. What is the formula to get the x cordinate on an object on a layer with a coefficient

I have a problem where I have an object on a back layer that I want to check if that object leaves the left side of the game (if x is lower than 0). However since that object is on a layer with a coefficient that is not 1.0 (say it can be 0.5 instead) when I check the x position of that object it is always changing depending on where I am when scrolling back and forth. How can I make it so it actually checks the x position of that object as if the coefficient was 1 so it is not changing all the time if that makes sense?  Reply With Quote

2. Off the top of my head, run a Fast Loop each frame that sets a layer's coefficient to 1 (use the Layer object), then check the object position in that loop. If it's lower than 0, destroy it. Then at the end of the loop, set the coefficient back to 0.5.  Reply With Quote

3. @Outcast : just move your object to a layer with coefficient 1.0 before testing, then check/store coordinates, move back to original layer.  Reply With Quote

4. I was keen to get this as a single formula too, so I could test it using a simple condition. It took me a while to figure out, but I believe I finally got there! The magic formula to see if any parallaxed object has gone off the left side of the game area is: I'm a bit less confident about the formula for testing whether something's gone past the right edge of the screen. Here's what I've come up with (it assumes the entire game area width is 1000.....that is, objects at x>1000 have left the game area): If someone could test these (especially the last one) to confirm they work, that would be great!  Reply With Quote

5. I don't know why, even though it sounds logical I can't get any of these methods to work  Reply With Quote

6. I think I found a way that works good for me though, instead of checking if the object is lower than an x position (in this case the very edge of the left frame = x = 0) I just positioned another invisible active at that position on the same layer and then compared my object to that object instead. So when my object is lower than that object (that object is position at x 0) then I trigger the event.  Reply With Quote

7. That's what I used to do. The thing is, no matter what method you use, this stuff is ultra confusing, at least to me.

Destroying an object when it goes beyond x works straight-forwardly enough for me, but when instead of destroying it you want it to wrap around from the other side of the game area, it gets weird.

Where it considers the left edge of the game and the right edge of the game varies wildly depending on where the camera is in the game. That seems obvious enough, but it does it in a way that's not at all intuitive to me. For example if you start on the left of the game area and travel to the right, objects will terminate and/or wraparound differently than they do if you start on the right of the game area directly. And this is the case with all the methods mentioned thus far (swapping layers, using formula, using reference object)

I've spent a day experimenting with this and I just can't get my head fully around how it works, even though it seems like it should be simple (and perhaps to someone else it would be.

This issue has bothered me on and off for years, and I thought I'd finally solve it by tackling it head on all day, but I'm still somewhat stumped as to how to get totally predictable wrapping. I'm happy with the formula though. It seems to produce the same results as the layer-swapping method, but is cheaper  Reply With Quote

8. I've also noticed that you can get vastly different results depending on where you have your "centre display at XXXX" event. For anything that references the frame positions (eg. my formula which uses X Left Frame), the "centre display at XXXX" event must be at the bottom of your events.  Reply With Quote

9. OK, I believe I've found the correct formula for finding the right edge of the game area. I was unsure about the previous one I showed, and it did seem to be wrong upon further testing. This is what I've found to work, to the best of my ability anyway, which is not necessarily saying much. In this example, the full width of the game area is 10,000. The equation is essentially this:

r = a - b + (b*c)

where:

r is the right edge of the game area, at any given time, regardless of camera position or layer scrolling coefficient
a is the full width of the game area
b is how much of the gameworld lies beyond the right edge of the screen (ie. full width minus X coordinate of right visible edge)
c is the layer coefficient of the object in question.

The first equation I showed, for the left edge of the gameworld, still appears to be correct. That one, incidentally, is:

L = d -(d*c)

where:

L is the left edge of the game area, at any given time, regardless of camera position or layer scrolling coefficient
d is how much of the gameworld lies beyond the left edge of the screen (ie. X coordinate of left visible edge)

(sorry for the triple post - blame the dumb forum rules that don't allow edits after 60 minutes).  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•