Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 623591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:06:33+00:00 2026-05-13T19:06:33+00:00

I am using the blitting technique that Jeff from 8bitrocket.com uses for creating tiles.

  • 0

I am using the blitting technique that Jeff from 8bitrocket.com uses for creating tiles. I am trying to paint 2 layers of bitmapdata onto a bitmap. One the first layer is the background ( 1 image). and the second layer is the tiles. In that class below. the updateMap is the method that gets called in the loop to repaint the image.

package com.eapi 
{
    /**
     * ...
     * @author Anthony Gordon
     */
    import com.objects.XmlManager;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.display.BitmapData;
    import flash.display.Bitmap
    import flash.geom.Rectangle;
    import flash.geom.Point;
    import flash.display.DisplayObject;

    public class EngineApi extends MovieClip
    {
        public var images:Array;
        public var world:Array;
        //w stands for world, how big it is in columns and rows
        private var wCols:Number = 50;
        private var wRows:Number = 16;

        public var wWidth:Number;
        public var wHeight:Number;
        //v stands for view, which means your field of view
        public var vRows:Number;
        public var vCols:Number;

        public var vWidth:Number = 540;
        public var vHeight:Number = 360;
        //how big your indivual tile is
        public var tileW:Number = 80;
        public var tileH:Number = 80;

        public var offsX:Number = 0;
        public var offsY:Number = 0;
        public var xEnd:Number = 0;
        public var yEnd:Number = 0;
        public var tilex:int;
        public var tiley:int;

        public var scrollx:Number = 0;
        public var scrolly:Number = 0;

        private var screen:Bitmap;
        private var canvas:BitmapData;
        private var buffer:BitmapData;
        public var mapHolder:Array;
        private var scrollLoop:Boolean;

        private var minLoop:Number;
        private var maxLoop:Number;

        public var currentMap:Number = 0;
        private var queue:Array;

        public var currentCol:Number = 0;
        public var currentRow:Number = 0;
        public var enviroment:Array;
        public var currentTileSheet:Number = 0;

        private var layer1:Sprite;
        private var layer2:Sprite;
        private var layer3:Sprite;
        private var layer4:Sprite;
        private var layer5:Sprite;

        public var background:BitmapData

        protected var stageObject:Array;
        protected var gameObjects:Array;

        public function EngineApi(w:Number = 540,h:Number = 360, tw:Number = 50, th:Number = 50) 
        {

            stageObject = new Array();
            gameObjects = new Array();

            //Add Layers
            layer1 = new Sprite();
            layer2 = new Sprite();
            layer3 = new Sprite();
            layer4 = new Sprite();
            layer5 = new Sprite();
            //end

            images = new Array();
            vWidth = w;
            vHeight = h;
            tileW = tw;
            tileH = th;
            queue = new Array();

            mapHolder = new Array();

            vCols = Math.floor(vWidth/tileW);
            vRows = Math.floor(vHeight/tileH);

            wWidth = wCols * tileW;
            wHeight = wRows * tileH;

            canvas = new BitmapData(vWidth,vHeight,true,0x000000);
            buffer = new BitmapData(vWidth + 2 * tileW, vHeight + 2 * tileH ,false,0x000000);           
            screen = new Bitmap(canvas);

            addChild(screen);

            addChild(layer1);
            addChild(layer2);
            addChild(layer3);
            addChild(layer4);
            addChild(layer5);
        }

        public function addGameChild(object:IGameObject, layer:Number):void
        {
            switch(layer)
            {
                case 1:
                    layer1.addChild(DisplayObject(object));
                break;
                case 2:
                    layer2.addChild(DisplayObject(object));
                break;
                case 3:
                    layer3.addChild(DisplayObject(object));
                break;
                case 4:
                    layer4.addChild(DisplayObject(object));
                break;
                case 5:
                    layer5.addChild(DisplayObject(object));
                break;
                default:
            }

            if (object.IsDisplay == true)
                gameObjects.push(object);

            stageObject.push(object);
        }

        public function UpDateMap():void
        {
            offsX += scrollx;
            offsY += scrolly;

            tilex = int(offsX/tileW);
            tiley = int(offsY/tileH);

            xEnd = tilex + vWidth;
            yEnd = tiley + vHeight;

            var tileNum:int;

            var tilePoint:Point = new Point(0,0);
            var tileRect:Rectangle = new Rectangle(0, 0, tileW, tileH);

            var rowCtr:int=0;
            var colCtr:int=0;

            for (rowCtr=0; rowCtr <= vRows; rowCtr++) {
                for (colCtr = 0; colCtr <= vCols; colCtr++) {

                    currentCol = colCtr+tilex;
                    currentRow = rowCtr+tiley;
                    tileNum = mapHolder[currentMap][rowCtr+tiley][colCtr+tilex];
                    tilePoint.x = colCtr * tileW;
                    tilePoint.y = rowCtr * tileH;
                    tileRect.x = int((tileNum % 100))* tileW;
                    tileRect.y = int((tileNum / 100))* tileH;
                    buffer.copyPixels(images[currentTileSheet],tileRect,tilePoint);
                }               
            }//End Loop
            var bgRect:Rectangle = new Rectangle(0, 0, 544, 510);
            var bgPoint:Point = new Point(0, 0);

            var bufferRect:Rectangle = new Rectangle(0,0,vWidth,vHeight);
            var bufferPoint:Point = new Point();            

            bufferRect.x = offsX % tileW;
            bufferRect.y = offsY % tileH;

            canvas.copyPixels(background,bgRect,bgPoint);
            canvas.copyPixels(buffer,bufferRect,bufferPoint);

        }//End UpdateMap

        public function StartRender():void
        {
            addEventListener(Event.ENTER_FRAME, loop);
        }

        protected function loop(e:Event):void
        {           
            UpDateMap();
            UpdateObjects();
        }

        protected function UpdateObjects():void
        {
            for (var i:Number = 0; i < stageObject.length; i++)
            {
                stageObject[i].UpdateObject();
            }

            for (var g:Number = 0; g < stageObject.length; g++)
            {
                if (stageObject[g].Garbage && stageObject[g].IsDisplay)
                {
                    removeChild(DisplayObject(stageObject[g]));
                    stageObject[g] = null;
                }
                else if (stageObject[g].Garbage == true && stageObject[g].IsDisplay == false)
                {
                    stageObject[g] = null;                  
                }
            }

        }

        public function StopRender():void
        {
            removeEventListener(Event.ENTER_FRAME, loop);
        }

    }

}

It’s not the complete code, but if I remove canvas.copyPixels(background,bgRect,bgPoint); or canvas.copyPixels(buffer,bufferRect,bufferPoint); I can see either or. If I paint them both then I can only see the one that painted last. My tile image is 128 x 32. 0 – 3. array 3 is transparent image. I used that hoping that I could see through the image and see the background. I was wrong.

At first it was an all black background, but then I changed the transparent constructor to true on the buffer variable. Now it shows a white background (like the stage), but still no background image.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:06:33+00:00Added an answer on May 13, 2026 at 7:06 pm

    I took a seperate movieclip and used it as a parallax behind the blitting tiles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Rails 3.2.0 with haml, sass and coffeescript: Basically I am trying to disable
Using mercurial, I've run into an odd problem where a line from one committer
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
(Using MVC 2) From inside my controller action, I need to display the url:
Using Java,I have to fetch multiple sets of values from an XML file to
Using report builder 3.0, I have a report that queries a cube. How do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.