Game Development Reference
In-Depth Information
//put buffer rect in corrct position what pixel
//to start the copy on in the left-hand top tile
camera.bufferRect.x=camera.x % mapTileWidth;
camera.bufferRect.y = camera.y % mapTileHeight;
//trace(bufferRect.x + "," + bufferRect.y);
canvasBitmapData.lock();
canvasBitmapData.copyPixels(camera.bufferBD,camera.bufferRect,
camera.bufferPoint);
canvasBitmapData.unlock();
}
private function drawPlayer():void {
if (player.velocity == 0) {
player.move = false;
}
if (player.move) {
player.animationDelay = player.maxVelocity - player.velocity;
player.animationLoop = true;
player.updateCurrentTile();
player.renderCurrentTile();
player.x = player.nextX;
player.y = player.nextY;
player.worldX = player.worldNextX;
player.worldY = player.worldNextY;
}else {
player.animationLoop = false;
}
if (getTimer() > carSoundTime +
carSoundDelayList[Math.abs(int(player.velocity))]) {
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_CAR, false, 1, 0));
carSoundTime = getTimer();
}
}
The drawCamera function
The drawCamera function is the core of the screen rendering code. The process we need run
through on each frame looks like this:
1.
Update the camera starting position.
2.
Find the starting tile row and tile column for the camera.
Search WWH ::




Custom Search