A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: how to create an isometric peg board?

Threaded View

  1. #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