我有两个js文件,都由一个HTML文件调用.
<script type="text/javascript" src="scripts/levelmovement.js"></script>
<script type="text/javascript" src="scripts/generation.js"></script>
Run Code Online (Sandbox Code Playgroud)
levelmovement.js的一部分:
function moveLevel(){
if(firstreset == true){
resetTime();
}
var time2 = new Date();
var millis2 = time2.getTime();
var millis3 = millis2 - millis1;
poschange = Math.floor(millis3 / 5);
for(i = 0; i < chunkpos.length; i++){
temppos[i] = chunkpos[i] - poschange;
if(temppos[i] <= -150){
temppos[i] += 1200;
generate(i);
}
pos = temppos[i];
document.getElementById('chunk' + i).setAttribute('style','left: ' + pos + 'px;');
}
}
Run Code Online (Sandbox Code Playgroud)
函数"moveLevel()"的调用方式如下:
window.onload = function(){
gameLoop();
}
function gameLoop(){
if(currentscreen == 'playing'){
moveLevel(); …Run Code Online (Sandbox Code Playgroud) 我尝试了以下内容,但没有奏效:
"开始"课程:
public class Start implements Runnable {
Start start;
LoadExample loadExample;
Thread mainThread;
Thread loadExampleThread;
private boolean running = false;
public static boolean isExampleLoaded = false;
public static void main(String[] args) {
begin = new Start();
loadExample = new LoadExample();
begin.start();
}
public synchronized void start() {
mainThread = new Thread(this, "Main");
mainThread.start();
loadExampleThread = new Thread(loadExample, "Load Example");
loadExampleThread.start();
}
public void run() {
running = true;
while (running) {
if(isExampleLoaded){
System.out.println("Loaded!");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
"LoadExample"类:
public …Run Code Online (Sandbox Code Playgroud)