Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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.

Comments on Why is the ground of my Dino game(in PDF) not moving and instead shrinking ?

Post

Why is the ground of my Dino game(in PDF) not moving and instead shrinking ?

+0
−3

Ground not moving instead shrinking when a cactus is spawnedI'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 ?

History

2 comment threads

Is the width of a "cactus" field the same as that of an "empty" field? (1 comment)
Debugging and expectations (1 comment)
Debugging and expectations
Karl Knechtel‭ wrote 3 months ago · edited 3 months ago

You say that the Ground_1 rectangle has the initial values [30 449 580 469]. In your own words, what do you expect these values to mean? Did you try to verify the meaning? How? In order for the rectangle to translate to the left, how should those values change (what should they become), logically? Is that what the code does? (Did you try to check the new values for the rectangle as update_ground is repeatedly called? How?)

Q&A sites, fundamentally, are about finding out information you didn't already have; not about getting someone else to examine a problem. Before asking the "why", please examine the "what" more carefully.

Please also keep in mind that we wouldn't be able to see the effect you describe to diagnose it; the "relevant" code is, yes, probably all that's relevant, but not enough for someone else to reproduce the issue.