Forum Topic: AS3: Drawing Rectangles and circles

(858 views • 2 replies)

This topic is 1 page long.

<< < > >>
Happy

m4x0

Reply To Post Reply & Quote

Posted at: 7/30/07 04:44 PM

m4x0 EVIL LEVEL 28

Sign-Up: 11/15/05

Posts: 3,239

Ok, so I'm pretty new to AS3, but I don't think anyone has wrote a tutorial on how to draw rectangles and circles to the screen using AS3, so I did. Here it is.

import flash.display.*;
//The above line imports the stuff needed to draw the shapes.

var mc1: MovieClip = new MovieClip();
//Creates a new empty movie clip called mc1

mc1.graphics.lineStyle(2);
//This defines the thickness of the outline of the shape, the lower the number the thinner the line.

mc1.graphics.beginFill(0xFF0000);
//This defines the coulour of the shape, replace the "FF0000" with the coulour you want, (Use THIS link to help you.

mc1.graphics.drawRect(250,250,100,100);
//This defines the size and position of the rectangle, the first number is the x position, the second number is the y position, the third is the width and the fourth is the height. To make a circle, simply replace "drawRect" with "drawCircle" and remove the last number, since the height and width of the circle will be the same.

this.addChild(mc1);
//the addChild command stores displayed objects in a list, the objects listed first are sent furthest back, the are no .Depth commands in AS3


None

LilFugitive

Reply To Post Reply & Quote

Posted at: 10/10/07 01:40 PM

LilFugitive EVIL LEVEL 16

Sign-Up: 06/01/06

Posts: 568

This tut is reasonably ok, but I think it not handy and useful to use when you can draw it in like 2 seconds

Ruining your life since 2006

BBS Signature

None

DougyTheFreshmaker

Reply To Post Reply & Quote

Posted at: 10/10/07 01:57 PM

DougyTheFreshmaker NEUTRAL LEVEL 02

Sign-Up: 07/30/07

Posts: 518

At 10/10/07 01:40 PM, LilFugitive wrote: This tut is reasonably ok, but I think it not handy and useful to use when you can draw it in like 2 seconds

That isn't really the point. For instance I had a .fla that, among other things, created a tile map from a file. There were tiles marked "collidable" all over the place, but I didn't want to have to collide all of my objects with every edge of every collidable tile. I ended up writing a routine that would mark only the edges which could realistically be hit by an object in the world (taken from the N tutorials, which was taken from somewhere else), but it wasn't acting correctly when I tested the file. So I ended up using the drawing API routines to help debug the method I had written. The screen shot attached shows how I used AS to draw the lines over the edges that the method detected as potentially collidable (after I got it working). Sure, these lines would have been easy to draw by hand in 2 seconds, but what good would that have done me?

I'm sure if you actually put some thought into it, you could see how it could be useful for other reason (including non-debugging ones)...

AS3: Drawing Rectangles and circles

We should take care not to make the intellect our god; it has, of course, powerful muscles, but no personality.
Freshmaking
Brainscrape

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 02:54 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!