A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: how to create an isometric peg board?

  1. #1

    how to create an isometric peg board?

    Does anyone know how I would modify this little bit of code to create a true isometric peg board? My logic to just shift the pegs down every other row is flawed. I apparently have to do something with 30 degree angles, but I can't seem to wrap my head around it

    Code:
    pegDistance = 50;
    pegNum = 1;
    for (i = 0; i < 10; i++){
    	for (j = 0; j < 10; j++){
    		this.attachMovie("peg","peg"+pegNum, pegNum, {_x:i*pegDistance, _y:j*pegDistance});
    		if (i%2){
    			this["peg"+pegNum]._y += pegDistance/2;
    		}
    		pegNum++;		
    	}
    }

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    for example this, or you could just nest two mcs, rotate one and scale another.
    who is this? a word of friendly advice: FFS stop using AS2

  3. #3
    Thanks for the tips! It seems I found a much simpler way of doing it though, which I have posted below.

    Code:
    isoRadians = 30 * Math.PI / 180;
    verticalDistance = 40;
    horizontalDistance = Math.cos(isoRadians) * verticalDistance;
    pegNum = 1;
    for (i = 0; i < 10; i++){
    	for (j = 0; j < 10; j++){
    		this.attachMovie("peg","peg"+pegNum, pegNum, {_x:i*horizontalDistance, _y:j*verticalDistance});
    		if (i%2){
    			this["peg"+pegNum]._y += verticalDistance/2;
    		}
    		pegNum++;
    	}
    }
    OR

    Code:
    isoRadians = 30 * Math.PI / 180;
    horizontalDistance = 40;
    verticalDistance = Math.tan(isoRadians) * horizontalDistance * 2;
    pegNum = 1;  
    for (i = 0; i < 10; i++){
    	for (j = 0; j < 10; j++){
    		this.attachMovie("peg","peg"+pegNum, pegNum, {_x:i*horizontalDistance, _y:j*verticalDistance});
    		if (i%2){
    			this["peg"+pegNum]._y += verticalDistance/2;
    		}
    		pegNum++;
    	}
    }
    I used this page to understand the logic of an isometric grid and this page to snag the math. The source code of the latter is great because it covers almost every situation where you know only a handful of attributes of a triangle.
    Last edited by sirzooass; 04-02-2009 at 07:28 PM.

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