Object's Y detection failure

Bugs will be moved here once resolved.

Post » Wed Jun 18, 2014 6:16 am

The problem has nothing to do with C2 being unable to be pixel perfect. The problem is incorrect math. You're doing the calculations for only one of them and expecting them all to work. You placed all initial tiles at y positions -256, 0, 256, and 512 in the first example and -256, 0, and 256 in the second. By adding 8 to the y position each tick you will always get the y at 768. But the space between each tile, 256 pixels, is not divisible by 9, so the ones not at y=0 or wherever you are calculating from end up missing.

Do the math, watch the y position in the debugger or just repeatedly add 9 to 512 and watch what happens. It misses 774 and 770. It's not about either of those being divisible by 9, the problem is you're not starting from the same y position for all of the tiles, so they're offset. That's why one row works, and the others don't.

What you need is a different method. For example, you can check is the spawners are not overlapping any tiles, and if so, get the y position of the highest tile, then create a new row of tiles at that position-256.
Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876

Post » Wed Jun 18, 2014 11:18 am

Arima wrote:The problem has nothing to do with C2 being unable to be pixel perfect. The problem is incorrect math. You're doing the calculations for only one of them and expecting them all to work. You placed all initial tiles at y positions -256, 0, 256, and 512 in the first example and -256, 0, and 256 in the second. By adding 8 to the y position each tick you will always get the y at 768. But the space between each tile, 256 pixels, is not divisible by 9, so the ones not at y=0 or wherever you are calculating from end up missing.

Do the math, watch the y position in the debugger or just repeatedly add 9 to 512 and watch what happens. It misses 774 and 770. It's not about either of those being divisible by 9, the problem is you're not starting from the same y position for all of the tiles, so they're offset. That's why one row works, and the others don't.

What you need is a different method. For example, you can check is the spawners are not overlapping any tiles, and if so, get the y position of the highest tile, then create a new row of tiles at that position-256.


Thanks I will try your stuff.
I was using a sprite trigger now though and have got the same gaps.
B
13
S
4
G
1
Posts: 241
Reputation: 1,724

Post » Wed Jun 25, 2014 2:34 pm

Closing as not a bug. See 'Expecting math calculations to be exact' under Common mis-used events and gotchas. The errors occur at the CPU hardware level and affect all software on your computer, not just Construct 2.

The problem probably stems from the 'Move at angle' action, which calculates cos(angle) and sin(angle), which are often slightly imprecise. Even so the correct solution is to compare within a small range instead of expecting exact results. In fact your example does not use delta-time so is framerate dependent; even better is to use dt and a one-off action once it goes below a threshold.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,351

Post » Wed Jun 25, 2014 10:37 pm

vagaev wrote:@Ashley

We can close this topic.
I realize I can't ask C2 to be pixel perfect.

The problem came from a delay between spawning the sprite and actually moving it. I accepted the fact that C2 can't handly such quick operations milliseconds perfect so I've come up with alternative solutions.

For those who might want to know. I just precreate 3 ranks of tiles and each time that for instance 3 blue collide with the sprite trigger i put those 3 new sprites in movement and immediately create 3 other sprites outside the layout ready to move.

For moving C2 does it very well.


hi
i see your description but i dont understand it well
can you send us .capx example ?
thanks
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Post » Thu Jul 03, 2014 2:29 am

hi
can you post an .capx example to see how you solve this problem ?
thanks
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Previous

Return to Closed bugs

Who is online

Users browsing this forum: Tony80 and 0 guests