How to make fill Rectangle without color in ActionScript 3.0 to see behind it - actionscript-3

I just started working on as3. I want to create a Rectangle but without color fill, so I can see what is behind it on stage. I love to draw on that Rectangle, but it never works without color fill.
var Canvas_sp:Sprite = new Sprite();
this.addChild(Canvas_sp);
//here i love Rectangle be without collor fill not whit(FFFFFF)e color
//i love see what behind the Rectangle and draw over it
Canvas_sp.graphics.beginFill(0xFFFFFF);
Canvas_sp.graphics.drawRect(0,0,550,400);
thx for all

If you don't want a fill, don't begin one.
Omit this line:
Canvas_sp.graphics.beginFill(0xFFFFFF);

To achieve the goal you want, you need to set the alpha parameter to 0, and maybe, to draw just a border of a Rectangle. You can see an example here: example
In your case, you can try something like this:
Canvas_sp.graphics.beginFill(0xffffff, 0);
Canvas_sp.graphics.lineStyle(0x000000, 0.1);
Canvas_sp.graphics.drawRect(0, 0, 550, 400);
Canvas_sp.graphics.endFill();

Related

How can we implement overlay effect in cocos2d for my game

We have a guy whose shooting range is denoted by a transparent circle. We want to have overlay affect in that transparent layer, as it works in Photoshop.
Basically that will highlight all the elements which comes in that range.
How can we do the same effect in cocos2d.
I don't know if it'll look exactly like you expect, but I'd do something like this:
For circle:
auto drawNode = DrawNode::create();
drawNode->drawDot(myPosition, myRadius, Color4F(0, 0, 0, 0.3));
//or use drawSolidCircle
now just add it wherever you want.
For "highlighting":
//loop through each all elements in range
element->setColor(someColor);
//or use shader, examples in cocos2d-x tests

Color dynamically drawn movieclip

I am allowing user to draw any shape dynamically and then i want to apply color for entire movieclip. say for example user has drawn circle, applying colortransform or graphics, colors only the circle line and leaving the inner portion of the circle uncoloured. I am using moviclip property graphics and allowing the user to draw anything. colortransform is not helping to color entire thing drawn dynamically, Is there any other way achive this. Is there any property to do this....
example Code:(not entire code)
drawArcMc.graphics.lineStyle(2,0xff0000);
drawArcMc.graphics.moveTo(startX,startY);
drawArcMc.graphics.lineTo(evt.stageX,evt.stageY);
Now if try to color this mc, only the line drawn get colored, not the entire mc(exmaple circle)..hope you get it, what i am trying to convey..Thanks in advace..
Try beginFill, like this:
drawArcMc.graphics.beginFill(0xff9900);
drawArcMc.graphics.lineStyle(2,0xff0000);
//draw your shape here..
drawArcMc.graphics.endFill();
so you should set the beginFill & lineStyle before you start drawing and endFill once you'r done..
You can use colorTransform to tint a movieclip. E.g.:
var color:int = 0xff0000;
mymc.transform.colorTransform = new ColorTranform(0, 0, 0, 1, (color & 0xff0000) >> 16, (color & 0x00ff00) >> 8, color & 0x0000ff);
This replaces any color in the movieclip with the color defined in the color variable.

Canvas fillStyle none in HTML5

I want to fill no color to canvas i.e. I want the background div color should keep on displaying in the div. I have googled it but didn't find any solution to keep fillStyle as no color.
Also I tried omitting the fillStyle but it leave me with black color.
Any options available?
Thanks
You need to use this to clear the canvas:
context.clearRect(0, 0, canvas.width, canvas.height);
(or the rectangle you need).
Also make sure you have no CSS rules set for the canvas element's background (which might be the case if your canvas is not transparent on init as canvas is transparent as default).
If you need to clear a non-regular shape you can use composite mode:
context.globalCompositeOperation = 'destination-out';
(xor and source-out can also be used too to a certain degree too to remove existing pixels but with some variations).
This will clear the canvas in the form of the next shape (Path) you draw (or use an image which solid pixels will clear the canvas).
I don't know what you're trying to do, but it seems you want to make your canvas transparent. You could do that in JavaScript:
context.fillStyle = "rgba(0, 0, 200, 0)";
Or in CSS, where foo would be the id of the canvas element. Note that this would make the element per se transparent, not just it's contents.
#foo {
opacity: 0;
}
You need to clear your canvas, not draw transparency... just think about that. You can't clean a glass, by using clear paint, the same is applied to the <canvas> element.
http://jsfiddle.net/Z6XTg/1/
this canvas demo does a very simple
ctx.clearRect(0,0,canvas.width,canvas.height);
before it draws anything, thus maintaining the canvas transparency.

Actionscript 3.0 drawRect works weird

I have a BitmapData object named myBitmapData. It was loaded of PNG of size 104x104. This PNG represents a red circle on the transparent background.
There is also a Sprite object named myBackground. I want render that red circle into myBackground.
myBackground.graphics.beginBitmapFill(myBitmapData);
myBackground.graphics.drawRect(0, 0, myBitmapData.width, myBitmapData.height);
myBackground.graphics.endFill();
addChild(myBackground);
Everything is fine. I see a red circle in the left top of myBackground.
But when I change the third line to
myBackground.graphics.drawRect(0, 52, myBitmapData.width, myBitmapData.height);
and expect my circle to be translated 52 pixels down, I actually obtain something strange (for me :)): there are two red half-circles (they form like hourglass).
So, the question is: how do I render myBitmapData into the random position of myBackground?
P.S.
In the case of
myBackground.graphics.drawRect(0, 104, myBitmapData.width, myBitmapData.height);
it is circle again :)
This is caused by beginBitmapFill's default repeat = true parameter. There's an example in the docs. Disabling the repetition won't work though, you'd just get a half circle then.
There are several ways to fix this:
Use a Matrix with a translation (displacement) as argument in beginBitmapFill.
Draw the rectangle at 0,0 on another Sprite, and move that sprite to where you want it on the background.
Don't draw directly to the background, but to another bitmap using copyPixels. Then fill the background with that bitmap.

as3: draw circle with a hole in it using only actionscript

Okay so basically I want to draw a circle in as3 that has a 'hole' in it (like a donut). Something like this, but without the outlines:
http://www.steel.ie/DugganSteel/Pictures/Hollow-circle.gif
This doesn't work:
SPRITE.graphics.beginFill(0xFFFFFF);
SPRITE.graphics.drawCircle(0,0,10);
SPRITE.graphics.endFill();
SPRITE.graphics.drawCircle(0,0,5);
I mean this seems like it'd be simple but I can't find any information on it. I should also mention that I'm trying to only draw 3/4 of the circle, like 3/4 of donut. So I was planning on drawing a transparent circle and square over the original circle, I know this seems kinda of weird since you'd expect something transparent to show whats underneath it.
Its actually really simple. See the following code:
var p:Point = new Point(100, 100);
graphics.beginFill(0xFF0000);
graphics.drawCircle(p.x, p.y, 100);
graphics.drawCircle(p.x, p.y, 50);
Intersections cancel each other out until you call endFill
Goodluck!
You can just make the line thickness the desired donut width and avoid using beginFill
set graphics.lineStyle
To make it only go 3/4 of the way around you could use curveTo to draw the 3 quarters.
The above method by Tyler works, however if an easier way to do it is to simply begin drawing the inner circle first. Basically Flash doesn't actually fill in the color until you call endFill() (again as mentioned by Tyler), so you start drawing on the inner circle, then the outer circle then on endFill() Flash fills in the gap.
SPRITE.graphics.beginFill(0xFFFFFF);
SPRITE.graphics.drawCircle(0,0,5);
SPRITE.graphics.drawCircle(0,0,10);
SPRITE.graphics.endFill();
Hope this clears things up for you.
Introduction to Flash drawing API, will help you understand a bit more :
http://www.senocular.com/flash/tutorials/flash10drawingapi/