Jump to content
  • Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

388 Neutral

About zqf

  • Rank
  1. I'm sure someone else would have something more elegant but this is some code I dug up out of an old project of my own for what sounds like a similar game, so it does work :p // This rectangle defines your screen size. Replace 640x480 with the size of your Flash app. // We will spawn enemies just outside this rectangle. var _screenRect:Rectangle = new Rectangle(0, 0, 640, 480); // This rectangle defines the range of positions enemies should spawn in. It will be adjusted // to match the size of the enemy being spawned during the set position method. var _spawnRect:Rectangle = new Rectangle(); // Return a random number between min and max. private function RandomWithinRange(min:Number, max:Number):Number { return Math.random() * (max - min) + min; } // Send a sprite class to this to move it off the screen. private function MoveOffscreen(enemy:Sprite):void { var spawnX:Number; var spawnY:Number; // We set the spawn rectangle to the size of the screen but // expand it out by the size of the object being spawned. // This will allow enemies of any size to always be moved off screen. var padX:Number = enemy.width; var padY:Number = enemy.height; _spawnRect.x = _screenRect.x - padX; _spawnRect.width = _screenRect.width + padX; _spawnRect.y = _screenRect.y - padY; _spawnRect.height = _screenRect.height + padY; // Pick randomly between X and Y, and move the spawn position to the full extent on // that axis. Then randomise the other axis. if (Math.random() > 0.5) { // We are setting the X to its full distance on the left or right, randomly pick which if (Math.random() > 0.5) { // left spawnX = _spawnRect.x; } else { // right spawnX = _spawnRect.width; } // Randomise the other axis. spawnY = RandomWithinRange(_spawnRect.y, _spawnRect.height); } else { // We are setting the Y to its full distance up or down, randomly pick which if (Math.random() > 0.5) { // Up spawnY = _spawnRect.y; } else { // down spawnY = _spawnRect.height; } // Randomise the other axis. spawnX = RandomWithinRange(_spawnRect.x, _spawnRect.width); } // Move the enemy to the new position enemy.x = spawnX; enemy.y = spawnY; }
  2. In a component based system how should I give sub-components references that their parent shouldn't have? eg: An Entity: maybe a monster, creates a Ray attack class for itself. The Ray Attack: This will cast the ray and receive the hit callbacks from the world, calculating the nearest hit (or more if the attack can penetrate) and hitting them. The World: which in my case at the moment is a box2D simulation. I want the child object, the ray attack to have access to the world (or more specifically, access to a single world method: 'QueryRay'. I don't want the parent entity to however. Should I pass it into some controller that will call a setup method on the ray attack that gives it the reference it needs perhaps...? At the moment my game passes around a 'services' class, containing interfaces to sub-controllers. This defines the capacity entities have to act outside of themselves. One of these is a 'rayAttack' controller that handles EVERY ray attack from anything, with the highly elegant: var rayAttack = services.rayAttack; rayAttack.Setup(a whole bunch of params); rayAttack.Fire(x0, y0, x1, y1); This is one example, I have all these central controllers bloating up with specific methods and I'd like to turn them into components but keep references tight to where they're needed only.
  3. zqf

    Flash Blitting Flicker

    Cleaned up a bit here it is. Language is Actionscript 3, only libraries used are Box2D for physics/collision, the rest is my own or standard Flash stuff. // On Frame draw call in Main public function Render():void { canvas.lock(); canvas.fillRect(canvas.rect, 0xff000000); _manager.currentState.Render(canvas); canvas.unlock(); } // In GameState public function Render(canvas:BitmapData):void { var mapRendPoint:Point = _gameModel.mapRenderPoint; // Position is taken from the box2D physics position of a camera entity tracking the player. // Subtract half screen width to get the top left point of the screen. var scrX:Number = _gameModel.camera.position.x * Main.PIXELS_PER_METRE - screenInfo.halfWidth; var scrY:Number = _gameModel.camera.position.y * Main.PIXELS_PER_METRE - screenInfo.halfHeight; scrX = Math.round(scrX); scrY = Math.round(scrY); mapRenderPoint.x = scrX; mapRenderPoint.y = scrY; // Render point is kept within the bounds of the tile map _gameModel.TileMap.CapRenderPoint(mapRenderPoint); // TileMap is given map position and adds every Tile to be drawn to the Draw List. _gameModel.TileMap.Render(mapRenderPoint); /* Game objects are added to the list */ // display list is called, this will actually run the calls to copy to canvas. draw list is then wiped _blitter.RenderFrame(canvas, mapRenderPoint); } // In Tile class, called from _blitter after TileMap has added all the tiles to be drawn public function Render(canvas:BitmapData, topLeft:Point):void {     // Translate to screen position     _rendPosition.x = _position.x - topLeft.x;     _rendPosition.y = _position.y - topLeft.y;     // Draw     canvas.copyPixels(_curFrame, _rendRect, _rendPosition, null, null, true); }
  4. Edit: Sorry I meant to post this in Beginners forum. I am creating a platformer where the entire game is blitted. The tile map seemed to be fine, however certain tiles with transparent pixels flicker very badly when the screen moves, appearing to change brightness rapidly, whilst other parts remain okay (I think). Please check out this little demo to see the effect (use WASD to move around). http://www.dampdogdev.com/devDemos/rngFlicker/flicker.html I've tried rounding the exact render position, flooring it, and double buffering but nothing I've tried seems to affect it.
  5. I dunno if this is helpful, and maybe this is covered by code you've removed to make your example smaller but an observation: Your renderer is defaulting to using the screen canvas as a source... public function Renderer(bitmapdata) { mBitmapData = bitmapdata; this.mDisplayBD = bitmapdata; ...If your Loader doesn't complete and replace the source then it will be copying the canvas onto itself and there's no load failure listener so if it fails you won't know about it.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!