A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: [Flash 8]Perspective skew

  1. #1
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506

    [Flash 8]Perspective skew

    Uses the same technique as percypeas mariokart engine, only with the bitmap data object:

    http://www.brokenbutton.com/perspective.html


    http://www.brokenbutton.com/perspective.fla

  2. #2
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    Lets just say I tried to do that and it didn't work .

    Nicely done.

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I tried to make it too, but no success. Great stuff

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Here I have modified the fla to work with keys:
    http://img336.imageshack.us/my.php?i...pective4as.swf
    Arrow keys to move, shift and control to rotate.

    It also loads bitmap from the library so there is no need to mc outside the stage.
    I still havent figured out how to rotate around the viewer and not around center of bitmap.

  5. #5
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    you need one extra level of nesting for the movement over the rotation.

    mc.mc._rotation

    mc.mc.mc._x
    mc.mc.mc._y

    This keeps the centre of rotation in the same place when you change x and y

  6. #6
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973
    Already tried mario kart with cacheasbitmap?

  7. #7
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Quote Originally Posted by lesli_felix
    you need one extra level of nesting for the movement over the rotation.

    mc.mc._rotation

    mc.mc.mc._x
    mc.mc.mc._y

    This keeps the centre of rotation in the same place when you change x and y
    Thank you, but I still dont understand. I dont even have any movie clips. There is only 1 mc and bitmap is attahed into it. Mc never moves. COuld you change the code perhaps to make it rotate around the viewer?
    Code:
    import flash.display.BitmapData;
    import flash.geom.Matrix;
    import flash.geom.Rectangle;
    import flash.geom.Point;
    import flash.geom.ColorTransform;
    var stageW:Number = 550;
    var stageH:Number = 300;
    var myCT:ColorTransform = new ColorTransform ();
    var fillColor:Number = 0xFF000000;
    var my_mc:MovieClip = this.createEmptyMovieClip ("mc", this.getNextHighestDepth ());
    var bm1:BitmapData = new BitmapData (stageW, stageH, false, fillColor);
    my_mc.attachBitmap (bm1, 0, "auto", true);
    var bm2:BitmapData = BitmapData.loadBitmap ("bricks");
    var degrees:Number = 0;
    var my_z:Number = 400;
    var my_x:Number = 0;
    var my_y:Number = -my_z / 2;
    var speed:Number = -5;
    mydraw ();
    onEnterFrame = main;
    function main () {
    	if (Key.isDown (Key.LEFT)) {
    		my_x += speed;
    		mydraw ();
    	} else if (Key.isDown (Key.RIGHT)) {
    		my_x -= speed;
    		mydraw ();
    	} else if (Key.isDown (Key.UP)) {
    		my_y += speed;
    		mydraw ();
    	} else if (Key.isDown (Key.DOWN)) {
    		my_y -= speed;
    		mydraw ();
    	} else if (Key.isDown (Key.SHIFT)) {
    		degrees += speed;
    		mydraw ();
    	} else if (Key.isDown (Key.CONTROL)) {
    		degrees -= speed;
    		mydraw ();
    	}
    }
    function mydraw () {
    	var radians:Number = (degrees / 180) * Math.PI;
    	bm1.fillRect (new Rectangle (0, 0, bm1.width, bm1.height), fillColor);
    	for (i = 1; i < stageH; i = i + 1 + (i / 100)) {
    		var xscale = stageW / 2 - i;
    		var eMatrix:Matrix = new Matrix ();
    		eMatrix.translate (-bm2.width/2, -bm2.height/2);
    		eMatrix.rotate (radians);
    		eMatrix.translate (-my_x, -my_y);
    		eMatrix.scale (i / 100, i / 100);
    		eMatrix.translate (stageW / 2, my_z - (2 * i));
    		var myRectangle:Rectangle = new Rectangle (0, i, stageW, 2 + (i / 100));
    		var smooth:Boolean = true;
    		bm1.draw (bm2, eMatrix, myCT, "normal", myRectangle, true);
    	}
    }
    You need image in the library with linkage name "bricks".

  8. #8
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    errrr, it's possible, but needs a lot of trigonometry. I've had this problem in the past. What you;ve done is very cool because it's totally dynamic, but using nested movieclips and taking the bitmap data from that is far easier, as you just need basic rotation and translation. I'll have a go at it later when I get a chance.

  9. #9
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Heyheyhey, I figured it out

    http://img53.imageshack.us/my.php?im...pective4we.swf
    (125kB, no preloader) Click to get focus. Arrow keys to move. Because its scaled, download it to your ocmputer to see real speed (quite fast).

    Not much different from last one, just changed some lines in the draw function.

  10. #10
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    That's really good!

    I'm going to have to have a go at optimising this sometime to see if it's worth getting a game out of it.

  11. #11
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Ok, I had a proper look at the code and i see how you did it, it's all to do with the order of the matrix translations. The matrix class seems to take care of a lot of calculations.

  12. #12
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Yes, matrix good

    Can I ask why you change the height of stripes?
    var myRectangle:Rectangle = new Rectangle (0, i, stageW, 2 + (i / 100));
    Taking same height stripes looks same way:
    var myRectangle:Rectangle = new Rectangle (0, i, stageW, 2);

  13. #13
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    To compensate for this line:

    for (i = 1; i < stageH; i = i + 1 + (i / 100)) {

    I was trying to speed things up by having thinner lines at the back and thicker lines at the top. It should look different if you take that out. gives you gaps between the lines.

  14. #14
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    i suppose all that's next is a getPixel function, if the pixel is black you've got collision baby.
    lather yourself up with soap - soap arcade

  15. #15
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Quote Originally Posted by lesli_felix
    To compensate for this line:

    for (i = 1; i < stageH; i = i + 1 + (i / 100)) {

    I was trying to speed things up by having thinner lines at the back and thicker lines at the top. It should look different if you take that out. gives you gaps between the lines.
    Ah, I see.
    What if you use
    for (i = 1; i < stageH; i ++) {
    with same height lines?

  16. #16
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    much slower, and much smoother looking. You're writing to the screen one pixel-line at a time.

  17. #17
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I wonder if that 1/100 pixels make any difference. As I understand it, the bitmapdata only deals with full pixels anyway, you cant take half pixels and copy it.

  18. #18
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    You're right, it went from one pixel, to two, and then to three. There's no point rounding if it does it automatically.

    The code was written in a hurry, so it's not the best way of doing it. It needs some playing around with.

  19. #19
    Senior Member ihoss.com's Avatar
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    581
    wow, that was a slow engien. What is the frame rate?

  20. #20
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    The most I can get out of it, when everything is moving, is about 20 fps. I really don't know if it can go faster.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center