Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Why is the ground of my Dino game(in PDF) not moving and instead shrinking ?
I'm creating a Chrome Dino-style game inside a PDF using JavaScript form fields . The ground is implemented using two adjacent button widgets that should continuously scroll left to create an infinite ground effect.
Instead of moving left as expected, the ground appears to "shrink" or compress over time.
Relevant code:
var GROUND_W = 550; // width of ground field
var GROUND_SPEED = CACTUS_SPEED;
var Ground_1 = this.getField("Ground_1");
var Ground_1_1 = this.getField("Ground_1_1");
function update_ground() {
var gr1 = Ground_1.rect;
gr1[0] -= GROUND_SPEED;
gr1[2] -= GROUND_SPEED;
Ground_1.rect = gr1;
var gr2 = Ground_1_1.rect;
gr2[0] -= GROUND_SPEED;
gr2[2] -= GROUND_SPEED;
Ground_1_1.rect = gr2;
if (gr1[2] <= 30) {
gr1[0] = gr2[2];
gr1[2] = gr2[2] + GROUND_W;
Ground_1.rect = gr1;
}
if (gr2[2] <= 30) {
gr2[0] = gr1[2];
gr2[2] = gr1[2] + GROUND_W;
Ground_1_1.rect = gr2;
}
}
The initial widget rectangles are:
Ground_1 : [30 449 580 469]
Ground_1_1 : [580 449 1130 469]
The intention is:
-
Both ground segments move left every tick.
-
When one segment completely leaves the screen, it should be repositioned immediately after the other segment.
-
The visible ground should maintain a constant width with no shrinking or gaps.
What could cause the ground to appear to shrink instead of simply translating left when a cactus is spawned ?

2 comment threads