00:00
00:00
Newgrounds Background Image Theme

NobeastcanDefeatme just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS3: Drawing Rectangles and circles

4,617 Views | 2 Replies
New Topic Respond to this Topic

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


BBS Signature

Response to AS3: Drawing Rectangles and circles 2007-10-10 13:40:20


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

Response to AS3: Drawing Rectangles and circles 2007-10-10 13:57:24


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