मैं एक जावास्क्रिप्ट टावर रक्षा प्रोग्राम शुरू कर रहा हूं; अब तक मेरे पास एक प्रक्षेपवक्र पर minions का आंदोलन है। लेकिन मुझे एक बहुत बड़ी परेशानी है, खेल अचानक कुछ सेकंड के लिए जमा हो जाता है। मैं अनुमान लगा रहा हूं कि कचरा कलेक्टर अपनी नौकरी कर रहा है, इस पर कोई विचार है कि मैं इसे कैसे हल कर सकता हूं, यह बहुत अच्छा होगा क्योंकि मैं गेम में बहुत सारे तत्व जोड़ने की योजना बना रहा हूं और जब तक मुझे प्राप्त नहीं होता तब तक मैं कोडिंग नहीं रखना चाहता यह पूरी तरह बहती है!जावास्क्रिप्ट गेम; धीमा और ठंडा! इसे कैसे हल करें?
अब तक कोड बहुत आसान है; आप इसे बाहर here
जांच कर सकते हैं कोड यह रहा:
<html>
<head>
<style>
#game{
background:red;
width:500px;
height:500px;
position:relative;
}
.mostro {
background:black;
width:15px;
height:15px;
position:absolute;
}
</style>
</head>
<body>
<div id="game">
<script type="text/javascript">
waypoint_x = [40, 140, 140, 220, 220, 80, 80, 340, 340, 420, 420];
waypoint_y = [140, 140, 60, 60, 240, 240, 320, 320, 100, 100, -20];
delay = 25;
new_monster = 0;
monsters_placed = 0;
monsters = [];
var d = new Date();
dist_x = 0;
dist_y = 0;
angle = 0;
mostro="";
total_monsters = 5;
function runGame() {
if (monsters_placed<total_monsters) {
new_monster++;
}
if (new_monster == delay) {
new_monster = 0;
document.getElementById("game").innerHTML = document.getElementById("game").innerHTML + '<div class="mostro" id="mostro-'+monsters_placed+'"></div>';
monsters_placed++;
}
for (i=0;i<monsters_placed;i=i+1) {
mostro = monsters[i];
dist_x = waypoint_x[mostro.point_to_reach] - mostro._x;
dist_y = waypoint_y[mostro.point_to_reach] - mostro._y;
if ((Math.abs(dist_x) + Math.abs(dist_y)) < 1) {
monsters[i].point_to_reach++;
}
angle = Math.atan2(dist_y, dist_x);
mostro._x = mostro._x + mostro.speed * Math.cos(angle);
mostro._y = mostro._y + mostro.speed * Math.sin(angle);
monsters[i]._rotation = angle/Math.PI*180-90
document.getElementById("mostro-"+i).style.left = Math.ceil(mostro._x) + "px";
document.getElementById("mostro-"+i).style.top = Math.ceil(mostro._y) + "px";
}
}
function setUpGame(){
for(i=0;i<=total_monsters;i++){
monsters[i] = new Object();
monsters[i].point_to_reach = 0;
monsters[i].speed = 1;
monsters[i]._x = 0;
monsters[i]._y = 0;
}
}
setUpGame();
setInterval(runGame,10);
</script>
</body>
</html>
क्या आपने अंतराल को 30 की तरह कुछ बढ़ाने की कोशिश की? – cloudhead
हां यह 1000 के – DFectuoso