I decided in my free time to try to write your project is a small game in flash.
As a method of displaying images I decided to use a BitmapData, which acts as a camera. At every update using the method draw draw all the game objects that fall within the camera field of view. However, in the process of implementation, there is one problem that I'm fighting for 3rd day.
When movement of the camera, there is a "lag" gaming background. The problem is that this is only a visual effect. In fact, one update takes time <1 MS so it's not about performance.
Actually the question. What is the reason for these "podragivanija"?
Architecture of the program:
1) Creates a timer which is responsible for updating elements of the game.
_timer = new Timer(1000 / FPS);//FPS == 60;
2)Main game loop
private function gameLoop(e:Event):void
//Counting the time that has passed since the last update
_date = new Date();
var deltaTime:Number = (isNaN(_lastUpdate))?0:(_date.getTime() - _lastUpdate) / 1000;
//START THE PROCESSING LOOP
//Updating command received from the player.
//Updating the model.
//Updating the camera position.
//Updated the display of the game.
//END PROCESSING LOOP
//Note the time at which he was update.
_lastUpdate = _date.getTime();
3) player controller.update() — updates the movement vector of the player and normalizes it.
There is a check for collisions.
In case of successful passage of all tests in the class of the player the method is called
this.x += movingDirection.x * speed * deltaTime;
this.y += movingDirection.y * speed * deltaTime;
5) update the camera position
private function updateCameraPosition():void
var levelWidth:int = _gameLevel.maxWidth / 2 - 1;
var leveHeight:int = _gameLevel.maxHeight / 2 - 1;
if ((levelWidth + 1) * LevelView.CELL_WIDTH > _gameController.player.x + GAME_WIDTH / 2
&& ( -levelWidth - 1) * LevelView.CELL_WIDTH < _gameController.player.x - GAME_WIDTH / 2)
_gameView.camX = _gameController.player.x;
if ((leveHeight + 1) * LevelView.CELL_HEIGHT > _gameController.player.y + GAME_HEIGHT / 2
&& ( -leveHeight - 1) * LevelView.CELL_HEIGHT < _gameController.player.y - GAME_HEIGHT / 2)
_gameView.camY = _gameController.player.y;
6) Updating the view.
public function update():void
camera.fillRect(new Rectangle(0, 0, _camWidth, _camHeight), 0);
7) Method drawLevelAndStuff()
private function drawLevelAndStuff():void
var minColumn:int = (camX - _camWidth / 2) / LevelView.CELL_WIDTH - 1;
var minRow:int = (camY - _camHeight / 2) / LevelView.CELL_HEIGHT - 1;
var maxColumn:int = minColumn + _camWidth / LevelView.CELL_WIDTH + 1;
var maxRow:int = minRow + _camHeight / LevelView.CELL_HEIGHT + 1;
var matrix:Matrix = new Matrix();
for (var i:int = minRow; i <= maxRow; i++)
for (var j:int = minColumn; j <= maxColumn; j++)
//Draw the cell coverage
matrix.translate(getLocalX(j * LevelView.CELL_WIDTH), getLocalY(i * LevelView.CELL_HEIGHT));
camera.draw(_level.getCell(i, j), matrix);
//Draw static objects
var stuff:IBitmapDrawable = _level.getStuff(i, j);
An example of the stick.
W — forward
S — back
The mouse turn. To start you need to click on the black circle :)
P. S. www.realmofthemadgod.com/
observed the same effect. If you focus on some element of coverage, the move shows that it does not move smoothly. I began to think that the problem in my eyes, but friends, including from their computers, see the same thing.