In a basic platform game created with JavaScript, the GameCharacter gets stuck in a jumping position once it detects a platform

I am currently working on a small platform game using JavaScript, and I've encountered an issue with the platforms. While my game character can jump properly, it seems to float just above the platform instead of landing on it. I suspect there may be a problem with the conditional statement responsible for detecting when the character should fall back to the ground.

Here is a condensed version of the code (which includes the game character function):

var gameChar_x;
var gameChar_y;
var floorPos_y;
var scrollPos;
var gameChar_world_x;

var isLeft;
var isRight;
var isFalling;
var isPlummeting;

var trees_x;
var treePos_y;
var collectables;

var game_score;
var ice_cream_store;
var lives;

var platforms;

var gameSound;
var jumpSound;
var gameOverSound;

// more code here...

https://i.sstatic.net/Cdxie.png

Answer №1

The issue has been resolved. The missing part was isFalling=false.

     for(var i=0; i<platforms.length; i++){
         if(platforms[i].checkContact(gameChar_world_x, gameChar_y)==true){
             isContact=true;
             isFalling=false;
             break;

Everything is now working perfectly. Appreciate all the helpful suggestions!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating to an element in Selenium with intern.js and leadfoot

Trying to pinpoint the issue with my current setup, as I'm facing a challenge. The problem arises when using intern.js for JavaScript functional testing in conjunction with SauceLabs. While the test itself passes without any errors, upon checking the ...

How can changes be spread to other stores within the react flux flow?

My project has a simple structure consisting of 1 store, 2 components (parent and child, with the parent acting as a controller), actions, and constants. Currently, I am not making any API calls; all data is passed to the parent component as props. The fl ...

Retrieving the onclick value in Selenium without the need to physically click the

Is there a way to access a value from a website without actually clicking on it? I need this specific value but due to bot blockers, interacting too much with the site is not an option. When inspecting the page by pressing F12, I can see the value I need i ...

JavaScript: selecting multiple elements with identical attributes

I'm struggling to target all a tags with the 'data-caption' attribute. I attempted to do this by: first selecting all the a tags let links = document.querySelectorAll('a'); and then trying to access their attributes links.get ...

Difficulties with angular ui-router authentication problems

When setting notify to true, the login.html does not render - it shows up as a blank page. However, if set to false, I receive multiple errors in the console: RangeError: Maximum call stack size exceeded at $.resolve (angular-ui-router.min.js:1) a ...

How to change class names dynamically in Vue.js?

I am looking for a way to dynamically change the background color based on a review rating using Vue.js. Ideally, I would like to achieve this with the following code: <div class="review" :style="reviewColor(hotel.average)"> In my methods section, ...

Utilize fancybox to target and display related content through external links within tabs

My website features a stylish box with tabbed inline content, allowing users to navigate between different views by clicking on tab names. However, I want the tabbed content to be accessible when a user clicks on a navigation link to launch the box. For ex ...

Using a jQuery dialog to launch a popup window specifically optimized for Safari browsers

I recently encountered an issue with my plain JavaScript function that opens a pop-up window. It functions perfectly in Chrome and Firefox, but I faced difficulty in Safari due to the default popup blocker preventing the page from opening without any err ...

JavaScript is incapable of locating image files

I am encountering Resource Not Found errors for the image files I am attempting to load into var manifest. Despite following the tutorial code closely, I can't seem to identify what is causing this issue... (function () { "use strict"; WinJS.Bin ...

The presence of onChange?: (ValueType, ActionMeta) => void with OptionType is not compatible

After updating to version v2.4.2, I keep encountering an error from flow regarding react-select. It seems that I am passing the correct types to the handle change, which expects an array with objects + OptionType accepting any string [string]: any. Can som ...

I keep receiving the same error (ENOENT) for all npm commands

Currently, I am running windows 8.1 x64 with all the latest updates installed. I encountered an error while using nodejs version 8.9.1 when running the command "npm -v". As a result, I decided to uninstall this version and switch to version 8.9.3. However ...

There are a couple of issues here: specifically, the `this.myMethod` function is not recognized as a function, and the click event added by the `addEventListener` function

I am currently attempting to create a timer using vue.js, but I am encountering some issues with my methods section: methods: { saveRunningMethod() { var runningData = { duration: `${this.hour} : ${this.minute} : ${this.se ...

Enable tabber upon clicking on the navigation bar

Hello there, I am facing an issue with my website's navigation. I have a navigation bar with the unique id #nav and I want to activate a specific tab based on the clicked navigation list item. The HTML structure of the navigation #nav looks like this: ...

Exploring Asynchronous File Operations in Node.js

I just started exploring Node.js and recently came across the fs module. I'm a bit puzzled by asynchronous versus synchronous file i/o operations. Let's analyze this test case: var fs = require('fs'); var txtfile = 'async.txt&ap ...

Tips for improving the product filtering functionality in a React application

To solve the problem, we need to develop a Filter.jsx component that will be responsible for filtering Products.jsx (available in the repository). Current React Components : Main.jsx import React from "react"; import { Products } from "../ ...

Issue with Firefox pageMod addon: window.location not functioning properly

I'm developing a unique Firefox Add-on that implements page redirects based on keyboard input. The keyboard detection is functioning properly, however, the redirect functionality seems to be failing. The complete code can be found on GitHub (even thou ...

Setting up TypeScript along with Babel and Webpack: A step-by-step guide

Here are the dependencies listed in my project: "devDependencies": { "@types/node": "^4.0.27-alpha", "babel-core": "^6.10.4", "babel-loader": "^6.2.4", "babel-polyfill" ...

Steering clear of using relative paths for requiring modules in Node.js

When it comes to importing dependencies, I like to avoid using excessive relative filesystem navigation such as ../../../foo/bar. In my experience with front-end development, I have found that using RequireJS allows me to set a default base path for "abso ...

creation of cascading drop-down lists

I have been struggling to create a dependent dropdown list using ajax and php, but unfortunately I am not getting the desired outcome. Below is my ajax code: <html> <head> <title>findperson</title> <script type="text/javascript ...

Adjusting the text size of upcoming elements using JavaScript

Currently, I am in the process of developing a basic chat bot. Upon receiving a new message from the server, a fresh HTML element is generated and sent to the browser. For instance, when message 1 is received, it will appear as follows: <div class="mes ...