Community

To:
Subject:
Message:
or Cancel

as2 bitmaps

Munsterkiler
Feb 29, 2012 (2 years 48 days ago)

France FR

hi,

i'm new to using bitmaps, and i realise (a bit late) that it can actually replace movieclips. My question is: am i doing it the right way? or are there better (more efficient, faster) ways to do it. I am just trying to place balls on the screen and make them move around.

import flash.display.*
import flash.geom.*
import flash.filters.*
function randRange(min:Number, max:Number):Number {
    var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
    return randomNum;
}
this.createEmptyMovieClip("balls", 100);
var ballbmd:BitmapData = new BitmapData(100,100,false, 0x000000);
_root.attachMovie("ball", "ball", 1);
ballbmd.draw(ball);
ball.removeMovieClip();
var bmd:BitmapData = new BitmapData(550,400,true, 0x000000);
var rect:Rectangle = new Rectangle(0,0,2,2);
var filter1:GlowFilter = new GlowFilter(0xFFFFFF, 100, 2, 2, 50, 2);
var numball:Number = 100;
for (i=0; i<numball; i++){
    _root["ball"+i] = new Object;
    _root["ball"+i].xpos = randRange(0, 550);
    _root["ball"+i].ypos = randRange(0, 400);
    _root["ball"+i].xspeed = randRange(-50,50)/10;
    _root["ball"+i].yspeed = randRange(-50, 50)/10;
}
onEnterFrame = function(){
    bmd.fillRect(bmd.rectangle, 0x000000);
    for (i=0; i<numball; i++){
        nam = _root["ball"+i]
        nam.xpos += nam.xspeed;
        nam.ypos += nam.yspeed;
        nam.xspeed = _root["ball"+nam.fol].xspeed;
        nam.yspeed = _root["ball"+nam.fol].yspeed;
        if (nam.xpos < 0){
            nam.xpos = 0;
            nam.xspeed *= -1;
        }
        if (nam.xpos > 550){
            nam.xpos = 550;
            nam.xspeed *= -1;
        }
        if (nam.ypos > 380){
            nam.ypos = 380;
            nam.yspeed *= -1;
        }
        if (nam.ypos < 0){
            nam.ypos = 0;
            nam.yspeed *= -1;
        }
        bmd.copyPixels(ballbmd, rect, new Point(nam.xpos, nam.ypos));
    }
    bmd.applyFilter(bmd, bmd.rectangle, new Point(0,0), filter1);
    _root.attachBitmap(bmd, 200);
}
  • Thankful People:
Back To The Forums