I haven’t really touched this project in quite a while because all my time was taken up with school, but now that I have time, I have just started working on it again. Now there is a strange bug that I can’t figure out how to fix.
The bug happens only when you make the main character, Qiste, move right. Making them move up, left, and down works perfectly, but moving right makes it work for a couple of frames, then a few frames after, the sprite goes to frame 2 of the walking animation, nothing happens, and after just a moment, it crashes. It’s almost like the engine is trying to render a costume that doesn’t exist. I’m guessing that because if you manage to successfully studderstep, it works, but it’s hard to do so.
Understand that in order to find the spritesheet for the player, go into the assets, click the Qiste folder, then enter the “Qiste spritesheet.png” texture atlas.
What is the problem? My computer does not have access to web developer tools, so I can’t see logs, only the pop-up errors that the engine shows, but it doesn’t have an error message either
After debugging the project, I found that the browser freeze is caused by an infinite loop in the cameraDeadzone script. The while loop gets stuck during movement, which causes the entire browser to freeze. Replacing the loop with a simple if statement to update the position once per frame fixes the issue.
CameraDeadzone.prototype.postUpdate = function(dt) {
var position = this.entity.getPosition();
var qistePosition = this.qiste.getPosition();
var limitX = deadZoneX / 50;
var limitY = deadZoneY / 50;
let targetX = position.x;
let targetY = position.y;
if (Math.abs(qistePosition.x - position.x) > limitX) {
targetX = qistePosition.x > position.x ? qistePosition.x - limitX : qistePosition.x + limitX;
}
if (Math.abs(qistePosition.y - position.y) > limitY) {
targetY = qistePosition.y > position.y ? qistePosition.y - limitY : qistePosition.y + limitY;
}
this.entity.setPosition(targetX, targetY, position.z);
};
Strange. I had the loop run so that Qiste is still on screen while they dash, which makes them move 6 times faster.
So why does the current version work while Qiste moves left, but breaks when Qiste moves right? If it’s an infinite loop problem, then shouldn’t both left and right cause the crash?
Instead of translating the camera, I was having it set the position with this.entity.setPosition((qistePosition.x - (deadZoneX / 50)),position.y,position.z) instead of using this.entity.translate((1/50),0,0). I don’t need to remove the “While”s in the code.
Edit: I understand what your code says now, and that would actually work out a lot better than what I have right now.
Note: We’ve moved away from using the ‘solved’ keyword in titles. Please use the built-in ‘solution’ button from now on. You can find the button to the left of the ‘like’ button on every post.