Comments (6)
My guess is that you're performing the splice inside the update enemies loop? If you splice during that loop, you'll miss updating one of the enemies in the list. That might be causing the flicker.
enemies = [0,1,2]
for (var i = 0; i < enemies.length; i++) {
console.log(enemies[i]);
if (enemies[i] === 0) enemies.splice(i,1);
}
// => output will be "0" "2"
from endless-runner-html5-game.
Any idea on how to make the enemy disappear when the player hits the enemy but will not cause it to flicker?
from endless-runner-html5-game.
If that's the cause of the flicker, you can manually increment i
when you don't splice instead of letting the loop do it.
for (var i = 0; i < enemies.length; ) {
console.log(enemies[i]);
if (enemies[i] === 0) enemies.splice(i,1);
else i++;
}
from endless-runner-html5-game.
This is the function that was used to update enemies position and draw.
function updateEnemies() {
// animate enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
enemies[i].draw();
// player ran into enemy
if (player.minDist(enemies[i]) <= player.width - platformWidth/2) {
//gameOver();
if (enemies[i] === 0)
{
enemies.splice(i, 1);
}
else
{
i++;
}
}
}
// remove enemies that have gone off screen
if (enemies[0] && enemies[0].x < -platformWidth) {
enemies.splice(0, 1);
}
}
It's not removing the enemy as it should.
from endless-runner-html5-game.
remove the if (enemies[i] === 0)
and just leave the enemies.splice(i,1)
.
from endless-runner-html5-game.
Thank you very much, it works.
from endless-runner-html5-game.
Related Issues (4)
- Mobile device compatibility HOT 4
- Enemy hitting player HOT 1
- Live Demo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from endless-runner-html5-game.