BitmapData.hitTest() How Accurate?
I am using BitmapData.hitTest() and want to know why it is not accurate. and the next question will be, how to make it accurate.
Code: public static function pixelHitTest(mc1:MovieClip,mc2:MovieClip):Boolean { var mc1bd:BitmapData = new BitmapData(mc1.width, mc1.height, true, 0); mc1bd.draw(mc1); var mc2bd:BitmapData = new BitmapData(mc2.width, mc2.height, true, 0); mc2bd.draw(mc2); if (mc1bd.hitTest(new Point(mc1.x, mc1.y), 0xFF, mc2bd, new Point(mc2.x, mc2.y))) { return true; } else { return false; } }
here is the link to show that it is not accurate. http://www.geocities.com/arian_m3/bitmaphittest.swf
thank you in advance
FlashKit > Flash Help > Actionscript 3.0
Posted on: 09-06-2007, 02:42 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[MX] Very Accurate HitTest
I require a accurate hitTest for my movie.
I have 2 odd shaped movie clips, a "ball" and a "square" (with a bit cut out).
I need to know if the two movies are over lapping. The problem is I can find this out using the following AS
ActionScript Code:
<font size="2">//on the ball movie cliponClipEvent(enterFrame){ if (this.hitTest(_root.square)) { trace("hits the square"); }}</font>
When I do this it gives the trace when overlapping the Binding Box and I need it to be very exact over the actual shape and contours of the Movie Clip.
Your help would be very much appreciated.
HitTest Not Too Accurate
Okay, creating a game where one object hits another. When I simply say
object1.hitTest(object2)
hitTest registers true even in cases where the objects aren't touching. As long as they're near each other, a hit is registered. So I tried
object1.hitTest(object2._x,object2._y,true);
This reverses things. Now, the two objects don't register a hit in situatiions that they should. They need to hit each other really well. Any ideas how to make the collisions more accurate? Thanks in advance.
BitmapData HitTest() Issue
I am having an issue with getting BitmapData hitTest() to work correctly. From the documentation (adobe live docs ActionScriptLangRefV3) I've read it should be able to do a pixel perfect hit test between two bitmaps however it indicates a hit when they are side by side. To emphasize the point I've placed the bitmaps apart by multiples of 5 and then right arrow to move across 5 at a time.
Please advise where I am going wrong?
package {
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.ui.*;
public class Step10 extends Sprite
{
var imgData1:BitmapData;
var bmp1:Bitmap;
var imgData2:BitmapData;
var bmp2:Bitmap;
public function Step10()
{
init();
}
private function init():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
imgData1 = new BitmapData(25, 25, false, 0xFF00FF00);
bmp1 = new Bitmap(imgData1);
addChild(bmp1);
imgData2 = new BitmapData(50, 50, false, 0xFF0000FF);
bmp2 = new Bitmap(imgData2);
bmp2.x = 50;
addChild(bmp2);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
}
private function keyDownListener(e:KeyboardEvent):void
{
if ((e.keyCode == Keyboard.RIGHT) && (bmp1.x < 480))
{
bmp1.x = bmp1.x + 5;
trace(" ");
trace ("bmp1 x" + bmp1.x);
trace ("bmp2 x" + bmp2.x);
if (imgData1.hitTest((new Point(bmp1.x, bmp1.y)), 0xFF, imgData2, (new Point(bmp2.x, bmp2.y))))
{
trace("Hit");
}
}
}
}
}
BitmapData.hitTest Method
Ive been working on a project where I need to get exact pixel based hit-test information from a dynamically imported png file. The code Ive attached works perfectly until the container_mc is moved on the stage, any thoughts or suggestions?
Code:
Attach Code
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
// Set default values for the image
var width:Number = 200;
var height:Number = 200;
var round:Number = 0;
var imgSource:String = 'sueNavImage.png';
// Create the containers for all the nessicary stuff
var contentContainer_mc:MovieClip = _root.createEmptyMovieClip('contentContainer_mc', _root.getNextHighestDepth());
var mask_mc:MovieClip = contentContainer_mc.createEmptyMovieClip('mask_mc', contentContainer_mc.getNextHighestDepth());
var content_mc:MovieClip = contentContainer_mc.createEmptyMovieClip('content_mc', contentContainer_mc.getNextHighestDepth());
var bitmap_bd = new BitmapData(width, height, true, 0x00000000);
// Try moving the content container, this breaks it.
contentContainer_mc._x = 0;
/* Note: Bitmap objects do not have coordinates, they dont exist on the stage.
A bitmap object isnt visible until its drawn into a movie clip. They do
have a width and height, but no _x and _y, this makes it a pain in the ass to
hit-test. */
// Add mouse listener
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
// when the mouse is down...
// create new point where the click happened
var currPoint:Point = new Point(_xmouse, _ymouse);
// calculate that point relative to registration point of the content container
contentContainer_mc.globalToLocal(currPoint);
// this is the broken part...
if(bitmap_bd.hitTest(new Point(0, 0), 255, currPoint)) {
trace(">> Collision at x:" + currPoint.x + " and y:" + currPoint.y);
}
}
Mouse.addListener(mouseListener);
// Load image
var content_mcl:MovieClipLoader = new MovieClipLoader();
content_mcl.addListener(this);
content_mcl.loadClip(imgSource, content_mc);
function onLoadInit(mc:MovieClip) {
// One the first frame is loaded do this
drawBox(mask_mc);
content_mc.setMask(mask_mc);
drawBitmap();
}
// a retarded monkey could figgure this one out
function drawBox(mc:MovieClip):Void {
mc.clear();
mc.lineStyle(0, 0x000000, 0);
mc.beginFill(0x666666);
mc.moveTo(0, round);
mc.curveTo(0, 0, round, 0);
mc.lineTo(width - round, 0);
mc.curveTo(width, 0, width, round);
mc.lineTo(width, height - round);
mc.curveTo(width, height, width - round, height);
mc.lineTo(round, height);
mc.curveTo(0, height, 0, height - round);
mc.lineTo(0, round);
mc.endFill();
}
// Draw a bitmap with no transformations
function drawBitmap() {
var colorTrans:ColorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
var matrixTrans:Matrix = new Matrix();
bitmap_bd.draw(content_mc, matrixTrans, colorTrans);
}
BitmapData.hitTest Questions
Let me preface this post by saying that I personally think that the BitmapData class is one of the most kick-*** (if not most cryptically documented) class I've ever used. It alone makes the upgrade to Flash8 worth it.
Ok, now that I've gotten that out of my system:
I've been exploring the hitTest method of the BitmapData class and I've found the method's parameters to be a little...odd... Flash doc states:
Code:
public hitTest(firstPoint:Point, firstAlphaThreshold:Number, secondObject:Object, [secondBitmapPoint:Point], [secondAlphaThreshold:Number]) : Boolean
Now, if I'm testing a BitmapData object against another BitmapData object, why is is necessary for me to include a firstPoint or secondBitmapPoint parameter? I've tried excluding them in my code but flash complains about a Type Mismatch.
Anyone know why flash wants these Point params?
-sp
Collision Detection BitmapData.hitTest
I'm curious as to what I'm doing wrong.
Here's a demo: http://theosoft.deviantart.com/art/F...lebee-91450740
Code:
package Bumblebee
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.ui.Mouse;
import flash.text.TextField;
public class Main extends Sprite
{
[Embed(source = 'media/bee.png')]
private var crosshairClass:Class;
private var crosshair:Bitmap = new crosshairClass ();
[Embed(source = 'media/yellow_flower.png')]
private var yflowerClass:Class;
private var yflower:Bitmap = new yflowerClass ();
private var yflowers:int = 5;
private var score_disp:TextField = new TextField();
private var score_txt:TextField = new TextField();
private var score:int;
public function Main():void
{
Mouse.hide();
score_disp.x = 5;
score_disp.y = 5;
score_disp.text = "Score: ";
addChild(score_disp);
score_txt.x = 40;
score_txt.y = 5;
score = 0;
score_txt.text = score.toString();
addChild(score_txt);
crosshair.height = 50;
crosshair.width = 50;
addChild(crosshair);
addFlower(yflower);
stage.addEventListener(Event.ENTER_FRAME, mouseMove);
stage.addEventListener(Event.ENTER_FRAME, flowerMove);
}
private function addFlower(flowername:Bitmap):void
{
flowername.height = 30;
flowername.width = 30;
flowername.x = 800;
flowername.y = Math.round(Math.random()*500);
addChild(flowername);
}
private function flowerMove(evt:Event):void
{
if (yflower.x > 0)
{
yflower.x--;
}
else
{
removeChild(yflower);
addFlower(yflower);
}
}
private function mouseMove(evt:Event):void
{
crosshair.x = mouseX - crosshair.width/2;
crosshair.y = mouseY - crosshair.height/2;
if (crosshair.bitmapData.hitTest(new Point(crosshair.x-25,crosshair.y-25),255,yflower.bitmapData, new Point(yflower.x, yflower.y),255))
{
/*yflower.x = Math.round(Math.random()*400);
yflower.y = Math.round(Math.random() * 400);*/
removeChild(yflower);
score+=100;
score_txt.text = score.toString();
addFlower(yflower);
}
}
}
}
BitmapData HitTest Problem On Rotation
Guys need help on BitmapData HitTest
I know there's a lot of code about hitTest ,and it works
but he problem is I have a rotation image that have unwanted behavior
if I rotate the image.
it works great if its a circle but not with other shape like box
seems like the boundary box problem
here's the code
var ptoint= new Point(ld2.x2,ld2.y2);
var pt2oint= new Point(elementTarget.x2,elementTarget.y2);
var bmapDataS:BitmapData = new BitmapData(ld2.width, ld2.height, true, 0x00000000);
var bmapDataT:BitmapData = new BitmapData(elementTarget.width, elementTarget.height, true, 0x00000000);
bmapDataS.draw(ld2, new Matrix());
bmapDataT.draw(elementTarget, new Matrix());
if (bmapDataS.hitTest(pt,0x80,bmapDataT,pt2,0x80)) {
ld2.removeEventListener(Event.ENTER_FRAME,enterFra meHandler3);
loop=0;
}
where ld2 and elementTarget is Loader and I load the Image using URLRequest
Thanks for the help
Finding Pixel Overlap With BitmapData.hitTest
Anyone know how to do this one?
I'm using BitmapData.hitTest to (obviously) hitTest between two PNGs. It works fine, in that it returns 'true' when the two images overlap. The problem is that I can't figure out how to identify the actual spot where the overlap occurs.
I can see the nature of the problem -- any number of pixels from image 1 might be overlapping any number of pixels from image 2.
Any ideas as to how I can generate a rect (or something like that) around the area where the overlap is occurring?
Thanks in advance for any thoughts.
BitmapData::draw(BitmapData) Doesn't Seem To Support Alpha Channels
Hi all,
I have a BitmapData object with alpha channels, bm1, and would like to draw it into another BitmapData object, bm2. While I can draw bm1 into bm2, alpha channels do not seem to work. Here is some code to illustrate what I'm trying to do:
// create an all-green but semi-transparent BitmapData object (all alphas are set to 0x80 in the constructor)
var bm1:BitmapData = new BitmapData(100, 100, true, 0x8000FF00);
// create an all-white BitmapData object and display it
var bm2:BitmapData = new BitmapData(100, 100, true);
addChild(new Bitmap(bm2));
// draw bm1 into bm2 in the onTimer() callback function
bm2.draw(bm1);
I would expect bm2 to be light-green, because it's semi-transparent, but it's 100% green, i.e., 0xFF00FF00.
I already tried all blend modes, but blend modes didn't make a difference.
Any ideas?
Btw, what I'm trying to do is to extract an arbitrary collection of pixels (as opposed to a rectangle) from a bitmap (bm1) by copying it into another bitmap (bm2) and using alphas of 0x00 and 0xff to select the pixels to be extracted. Is there a better way to do this? (or any way for that matter? ;-)
Thanks!
-Bernd
[as3] Drawing BitmapData To Erase BitmapData
Hey there. I'm still working on my paint program, and I figured I'd try using the open source, raster-based drawing system from Bytearray.org to speed up drawing in some of my paint tools. The Raster class has some drawing functions that don't bother with anti-aliasing, so in some situations, implementing these methods results in faster code than relying on the Graphics package. I've gotten a nice speed boost from my rainbow paintbrush, which is pretty neat. Go open source!
Unfortunately, I can't get the eraser brush to work, even though its code is essentially the same as the other brushes'. And I've figured out why; the "erase" and "alpha" blend modes, which my vector-based eraser uses to erase the drawing surface, don't seem to work when you draw one BitmapData object onto another. I could put the BitmapData in a Bitmap object and draw that, but that's essentially converting raster data to vector, and then back to raster, which is far slower than any speed improvement I'd get from relying on the Raster class in the first place.
Has anyone here succeeded in using one BitmapData object to erase another, without "wrapping" the eraser BitmapData in a Bitmap object?
SetInterval Accurate?
I'm having problems with setting the interval for a function........
Im using this to synchronize two soundobjects. The sound objects are exactly the same length in milliseconds.
First I get the duration of one of the loops. Then I set to interval for the function that starts the second loop exactly to the loop length.
But it doesnt seem to be stable........... sometimes it times it correctly sometimes it's a bit off.
Here's my code:
Code:
s1 = new Sound(this);
s1.attachSound("loop1");
s2 = new Sound(this);
s2.attachSound("loop2");
loopLength = s1.duration;
s1.start(0, 999);
// doSyncStart function
function doSyncStart() {
if (syncStart == true) {
s2.start(0, 999);
syncStart = false;
}
}
setInterval(doSyncStart, loopLength);
I use a button to set the variable "syncStart" to true.
If anyone can give me some insight as to why this is so inaccurate or maybe a way to optimize the code, it would be greatly appreciated
P.S. I've tried the highest movie fps rates but it didnt make much of a difference
SetInterval Accurate?
I'm having problems with setting the interval for a function........
Im using this to synchronize two soundobjects. The sound objects are exactly the same length in milliseconds.
First I get the duration of one of the loops. Then I set to interval for the function that starts the second loop exactly to the loop length.
But it doesnt seem to be stable........... sometimes it times it correctly sometimes it's a bit off.
Here's my code:
Code:
s1 = new Sound(this);
s1.attachSound("loop1");
s2 = new Sound(this);
s2.attachSound("loop2");
loopLength = s1.duration;
s1.start(0, 999);
// doSyncStart function
function doSyncStart() {
if (syncStart == true) {
s2.start(0, 999);
syncStart = false;
}
}
setInterval(doSyncStart, loopLength);
I use a button to set the variable "syncStart" to true.
If anyone can give me some insight as to why this is so inaccurate or maybe a way to optimize the code, it would be greatly appreciated
P.S. I've tried the highest movie fps rates but it didnt make much of a difference
SetInterval Not Accurate Enough
I am coding a metronome for drummers. I need to call a function accuractly within 100 ms or less. There is a slight stutter when producing a beat every time with a milliseconds this low. I'm not sure if the mp3 file is causing the stutter. Is there anyway I can eliminate this? When is trace simple output text, I can't tell if its accurate or not to see if the mp3 is the problem.
Any ideas?
Thanks for your time!
How Accurate Is GetTimer()?
I'm working on a tetris clone and I'm trying to decide on the top of scoring system to implement. I think I'm going to go with a score that depends on the time it takes for the tetris piece to reach the bottom of the screen.
Anyways, my question is how accurate is GetTimer()? A lot of stuff is happening indepedent of the timeline FPS, so if I assigned the value of GetTimer() to a variable once I drop a new tetris piece and then subtracted this from the value of the same tetris piece once it stops falling, am I going to get an accurate measure of the time it took for the tetris piece to fall?
[F8] Specifying More Accurate Cuepoints?
Hey all,
Im trying to call a function at certains beats in an mp3. To do this I want to use cue points and to type them manually for control. However, I cant get the timing more accurate than in seconds using actionscript, it doesnt seem to understand sat 2.5 as opposed to 2. Maybe the syntax is wrong? This is the code I am using to do it.
var aCuePoints:Array = [{cue:3, msg:"Cue point 1"},
{cue:5, msg:"Cue point 2"},
{cue:7, msg:"Cue point 3"},
{cue:9, msg:"Cue point 4"}
]
var sndMusic:Sound = new Sound();
sndMusic.loadSound("Neverending.mp3", true);
var nCuePointCheck:Number = setInterval(checkCue, 1000);
function checkCue():Void{
for(var i:Number=0; i<aCuePoints.length; i++){
if(aCuePoints[i].cue == Math.floor(sndMusic.position/1000)){
trace(aCuePoints[i].msg);
break;
}
}
}
As you can see the cue points are at 3, 5, 7 seconds etc but i need them inbetween.
Any help would be MUCH appreciated!
I dont know any XML either and embedding them into the movie makes them difficult to alter.
More Accurate Slider
Hi
I'm trying to make a slider that is very accurate. Currently, I have one that is 300 pixels wide, and I'm using the offset of the hand (._x) property to determine where the handle is. Clearly, the large the slider, the more accurate it gets.
But I need more accuracy with a slider the same size. I need more significant digits. As it stands, if I were to display the percentage of the slider position (offset / 300px), it gives me .33, .66, 1, 1.33, etc. I need more accuracy for what I am doing.
How would I go about doing this? Is there a way I can make is more accurate?
Thanks in advance,
Alexandre
Number Not Accurate
i=-5
while(i<=5) {
trace(i);
i+=0.1;
}
I'm using MX, but the result not increase 0.1. How to solve it?
Use Counts Accurate?
kornfused...
I am trying to get a big flash file organized, but when I choose the "Select Unused Items" in the library palette drop down menu, Flash identifies a lot of items which have use counts more than zero in the use count column.
I'm wondering which is correct and why this is happening?
Accurate Scoring
Id like to track a user score after they drag a series of objects to the correct location. Ive come up with the following way but this solution increases and decreases the score simply if the mouse is clicked on the object. Does anyone know of a way to prevent this?
Ive attached a sample to clarify what I mean.
Thanks
Accurate Hit Counter
Hi,
I'm in the process of creating a hit counter (number of visitors counter) using Flash. I already seen the PHP based counter here on kirupa.com but it is not accurate enough as it will increment upon each page refresh. I would like to get a more accurate statistic about the number of different visitors rather than the number of page loads.
What I was thinking about was getting and storing the IP addresses and only incrementing the counter if the IP address is not yet known. This will give a higher accuracy but is still not perfect. Does anyone have any better idea?
Many thanks in advance for your help!
Can't Get Accurate Mc Height
Hi
I am attempting to put a vertical menu bar, each made up of a text fields inside a mc. The mcs and text create fine, but I am having "FUN" trying to position them vertically.
In the snippet below you can see that I go round a loop and format the mcs etc - all works. However, when I use trace(linkBtn._height) I get the same value for every button and some are right, some are wrong.
Strangley If I pick one specific button out using the if(i==6) {... it tells me a different height (which happens to be correct)
What's going on? And more importantly, how do I get the correct heights.
Thanks in advance
Edward
Code:
for (var i:Number = 0; i < RootNode.childNodes.length; i++) {
//get the text for the designMenu links
linkText = RootNode.childNodes[i].firstChild.nodeValue;
if (i == 0) {
designMenu.text = linkText;
designMenu.setTextFormat(btnRollOff_fmt);
designMenu.antiAliasType = "advanced";
designMenu.embedFonts = true;
trace(i + "=" + designMenu._height);
} else {
//bring in a movie clip that will form the link
var linkBtn:MovieClip = attachMovie("link_mc", "linkBtn" + i, getNextHighestDepth()); linkBtn.createTextField("linkTxt", getNextHighestDepth(), 0, 0, 169, 0); linkBtn.linkTxt.setNewTextFormat(btnRollOff_fmt); linkBtn.linkTxt.autoSize = "left";
linkBtn.linkTxt.wordWrap = "true";
linkBtn.linkTxt.border = "true";
linkBtn.linkTxt.antiAliasType = "advanced";
linkBtn.linkTxt.embedFonts = true;
linkBtn.linkTxt.text = linkText;
trace(i + "=" + linkBtn._height);
if (i == 6) {
trace("number" + i + "=" + linkBtn._height);
}
}
}
Accurate Scoring
Id like to track a user score after they drag a series of objects to the correct location. Ive come up with the following way but this solution increases and decreases the score simply if the mouse is clicked on the object. Does anyone know of a way to prevent this?
Ive attached a sample to clarify what I mean.
Thanks
Accurate Buttons?
Basically I have a button that when you mouse over plays a movie clip. WHen you mouse out, the movie clip stops playing. However, no matter what combinations on rollover, dragover, dragout, I am finding that sometimes if you move fast enough over the button the on dragout, mouseout whatever combinations don't work and the movie clip still plays, even if you are no longer over the button.
I've seen in several sites features like this (its very commonly used), but how do they get theirs to work in all situations?
Any help would be appreciated!
SetInterval Accurate?
Last edited by DeeLight : 2002-12-06 at 17:48.
I'm having problems with setting the interval for a function........
Im using this to synchronize two soundobjects. The sound objects are exactly the same length in milliseconds.
First I get the duration of one of the loops. Then I set to interval for the function that starts the second loop exactly to the loop length.
But it doesnt seem to be stable........... sometimes it times it correctly sometimes it's a bit off.
Here's my code:
-----------------------------------------------
s1 = new Sound(this);
s1.attachSound("loop1");
s2 = new Sound(this);
s2.attachSound("loop2");
loopLength = s1.duration;
s1.start(0, 999);
// doSyncStart function
function doSyncStart() {
if (syncStart == true) {
s2.start(0, 999);
syncStart = false;
}
}
setInterval(doSyncStart, loopLength);
-----------------------------------------------
I use a button to set the variable "syncStart" to true.
If anyone can give me some insight as to why this is so inaccurate or maybe a way to optimize the code, it would be greatly appreciated
P.S. I've tried the highest movie fps rates but it didnt make much of a difference
Accurate Representation
I have a flash file which has a canvas size of 1024x768. Some elements in the background are much larger than that. When playing this file via the published html file on 1024x768 screen resolution, some of it i cut off obviously due to the toolbars and such and when playing with higher screen resolutions, the aforementioned background isn't cut off at 1024x768. Is there a script or a different way of publishing which will provide an accurate representation of what the file will actually look like when played in full screen mode via the web?
Is GetTimer Actaully Accurate
Im using GetTimer in my movie, but it seems to fluctuate.
Should it be completely accurate, or can it vary like the framerate does?
Anyone else notice this, or is it something Ive done wrong?
How Can I Provide ACCURATE HitTesting?
i hav my "level" mc and my "character" mc. each frame the variable "fall", with equals 10, is added to "character"'s _y. but if the character is like 4 pixels above the level, the character lands 6 pixels in the ground. does anybody kno how 2 prevent this? im using this code on the level:
onClipEvent (enterFrame) {
with (character) {
if (level.hitTest(_x, getBounds(_root).yMax, true)) {
_y -= fall;
}
}
}
Bandwidth Profiler, Is It Accurate?
Is the bandwidth profiler accurate, in terms of its 56k setting? It seems a fair bit slow. If not what is a good average bytes per second on a 56k connection.
Also, if anybody knows the average bytes per second for a DSL and Cable connection. On average
Thanks
To Pull Only The Accurate Amount.
I am with a small problem, is the following one, I have my main file that this calling 10 swfs external, example in frame 1 calls one swf, in frame 150 calls another one, in frame 230 calls another one and thus it goes until completing the 10 swfs, I am using something thus for each swf "tran1_mc.loadMovie(_root.i11)", in the HTML if I to place 10 swfs it pulls normal, all certainty so far, but if in my HTML to say only it to pull 3 swfs, it pulls these 3 swfs and the remaining portion is blank, what necessary to make it is when to finish to show to this 3º swf it comes back to the first one, somebody has an idea of as I can make this?
Xmouse And Ymouse Not Accurate
I have a problem... I have a game that's getting rather complex, and I'm switching the controls over from a keyboard method, to a mouse method. The idea is to have the character's rotation automatically adjusted so he's always facing the mouse. (Which I've got working fine)
The problem is, the mousex and mousey are not updating properly. How I'm pulling the information is like this:
code:
onClipEvent(load) {
_root.cursor = new Object;
_root.cursor.interval = function() {
_root.cursor.x = _root._xmouse;
_root.cursor.y = _root._ymouse;
updateAfterEvent();
}
setInterval(_root.cursor, "interval", 1);
}
Now, when I put this movieclip & script in to a new fla that doesn't have the processing overhead that my game does, the cursor.x and cursor.y stay updated just fine (because it's updating them every 1 miliseconds, instead of at the normal frame rate). However, when it's in my game, If I move the mouse quickly, I can "leave flash behind", meaning that my cursor is across the screen, yet flash still thinks that the mouse is still sitting idle where I just left it.
This isn't just a matter of flash "catching up" because of processor load, because I can sit there forever and the variables will not update. I have to move my mouse around for it to return the correct data.
What I am assuming is happening, is that the _xmouse and _ymouse variables only update themselves when flash notices the mouse has moved, and if the processor is busy with other things, the _xmouse and _ymouse might not update. Am I correct in this? And if so, is there a way to force flash to update it's _xmouse and _ymouse variables, regardless of whether flash thinks the mouse has moved or not?
Has anyone else had a problem like this?
Thanks,
Chris
Frames Not Accurate When I Play The .fmw
Hi, I have a problem when I export my movie. First, I will explain what the fmw contains.
Two chapters (chapter one works fine)
In the second chapter I have:
background sound (me speaking)
background video
Images and video clips up in the corner.
This might sound like alot, especially since I have a big video, but listen to the problem first. What I want to do is that the pictures and images in the corner should appear at the exact moment when I say certain stuff. So I moved them in the layers and previewed the chapter each time to get it exactly right. Later, when I previewed the entire .fmw including the first chapter everything was totally out of sync by many seconds. I did a bit of checking, and as it turned out, the images doesnt appear at the correct place when I only preview the second chapter. So I tried to put the second chapter in a seperate file and export it standalone, but even then it doesnt appear correctly. The images only appear on the exact frame when I export it together with the first chapter, which makes it impossible to keep working on it since I dont want to watch through the first chapter for every time I test it.
Oh, another thing I noticed is that the problem lies in that the images appear too late. Which means, if I want to switch images after 120 frames (10 seconds), it might actually switch after 148 frames (12 seconds) when I play the preview of chapter 2.
Limits Of Accurate Timing?
Hi, I'm trying to create a drum machine.
To do this I need to be able to accurately trigger drum sounds every sixteenth note, or around once every 125ms, even more often at higher tempos.
I've created a timer at this interval to play the sound, but even with some error correction I read about (checking against getTimer and compensating) it's pretty inaccurate.
Is there any way to reliably play sounds at this small interval?
Thanks for any help!
Brian
ps. I'm new to making internet apps. If this is beyond what Flash is designed to do, are there other products/languages that could handle this?
100% Accurate Countdown Timer?
Hi,
BACKGROUND
I need to make a countdown timer in Flash that will countdown in seconds to the next whole hour and then will reset and countdown to the following next hour
The timer needs to be 100% accurate.
QUESTION
Is it possible to create a countdown timer in actionscript which will be perfectly accurate - ie. will always be identical when compared with actual rea-life time, irrespective of the hardware, processing of applications done on a client machine?
If this is not possible, is it possible to include in the code a detection of when the timer becomes inaccurate and then further code to get it back on track to correct the inaccuracy?
Any code examples/links to tutorials regarding above issues would be greatly appreciated.
Thanks
Accurate Preloader For FLV Streaming
Hi Everyone,
I'm working on accurate preloader for FLV video... The problem is that since it's streamed video it starts to play once it buffers enough of it (usualy around 8% to 15%)... So this 8% to 15% is the 100% of the loader bar but since it's changes from video to video I'm trying to find out how I can get this percentage before hand to estimate total size of preloading segment... Is there any way to do it in AS 2.0 (or AS 3.0)? How much of the FLV does Flash needs to preload to start playing video?
I'm using Flash CS and AS 2.0 for this project...
Any hints, thoughts, links and resources will be greatly appreciated...
Thanks for your time,
Peter
Accurate Collision Detection (AS3)
i draw some random shaped on a movie clip using MovieClip.graphics tools. now i want to detect collision of that shape with another movie clip.
hittestobject() on movieclip only does the bounding box detection. can anyone help me to do more precise detection as bounding box detection is useless in my case.
Strange: If Evaluation Not Accurate...?
I'm observing a strange occurrence. When I evaluate for the following:
Code:
//Create Logo Holder & Position
if(Stage.width > 210 && Stage.height > 210){
_level0.attachMovie("Logo", "LogoClip1", 1, {_x: 0, _y: 0});
_level0.LogoClip1._alpha = 50;
}
else{
_level0.attachMovie("LogoTile", "LogoClip2", 1, {_x: -15, _y: 5});
_level0.LogoClip2._alpha = 50;
}
I would assume that if my movies dimensions we set to 209 x 209, my second case would execute. However, after some testing I've determined the result is that case 1 will not execute until my movie dimensions are set to 311 x 311. This is weird.
Below is my entire move script:
Code:
//Disable Context Menu
Stage.showMenu = false;
//Set Stage
Stage.scaleMode = "noScale";
Stage.align = "TL";
//Import path
var vidPath = path;
//Create Logo Holder & Position
if(Stage.width > 210 && Stage.height > 210){
_level0.attachMovie("Logo", "LogoClip1", 1, {_x: 0, _y: 0});
_level0.LogoClip1._alpha = 50;
}
else{
_level0.attachMovie("LogoTile", "LogoClip2", 1, {_x: -15, _y: 5});
_level0.LogoClip2._alpha = 50;
}
function positionLogo1(clip) {
clip._x = Math.round((Stage.width/2)-(215/2));
clip._y = Math.round((Stage.height/2)-(60/2));
}
//Create HolderMC & Load sample
var j:MovieClip = this.createEmptyMovieClip("Holder_mc",0);
var mcl:MovieClipLoader = new MovieClipLoader();
var mcl_listener:Object = {};
mcl_listener.onLoadInit = function(target_mc:MovieClip) {
target_mc._visible = true;
positionLogo(_level0.Logo);
}
mcl_listener.onLoadProgress = function(target_mc:MovieClip,bl:Number,bt:Number) {
trace(target_mc + " has loaded: " + bl + " of total: " + bt);
}
mcl.addListener(mcl_listener);
mcl.loadClip(vidPath,j);
positionLogo1(_level0.LogoClip1);
stop();
But I don't see what could be causing that kind of oddity.
Any clues?
100% Accurate Countdown Timer?
Hi,
BACKGROUND
I need to make a countdown timer in Flash that will countdown in seconds to the next whole hour and then will reset and countdown to the following next hour.
The timer needs to be 100% accurate.
QUESTION
Is it possible to create a countdown timer in actionscript which will be perfectly accurate - ie. will always be identical when compared with actual rea-life time, irrespective of the hardware, processing of applications done on a client machine?
If this is not possible, is it possible to include in the code a detection of when the timer becomes inaccurate and then further code to get it back on track to correct the inaccuracy?
Any code examples/links to tutorials regarding above issues would be greatly appreciated.
Thanks
Flv Seek Control Not Accurate
i am trying to write a function that will play a segment of an flv.
I am using a blank movie clip called "timer" to keep track of things and pause the video at the appropriate time
ActionScript Code:
var my_nc = new NetConnection();
my_nc.connect(null);
var ns = new NetStream(my_nc);
vid_holder.attachVideo(ns);
function loadvideo(what, startTime) {
vid_holder.attachVideo(ns);
ns.play(what+".flv");
ns.onStatus = function() {
ns.seek(startTime);
ns.onStatus = null
};
}
function playToFrom(file, startTime, endTime) {
loadvideo(file, startTime);
timer.onEnterFrame = function() {
currentTime = ns.time;
if (currentTime>=endTime) {
ns.seek(endTime);
ns.pause();
this.onEnterFrame = null;
}
};
}
it seems when i call
ActionScript Code:
playToFrom("game1", 10, 15);
it seeks to 10.99 (almost a second late)
does anyone have any information or a link that might be helpfull.
thanks.
To Pull Only The Accurate Amount.
I am with a small problem, is the following one, I have my main file that this calling 10 swfs external, example in frame 1 calls one swf, in frame 150 calls another one, in frame 230 calls another one and thus it goes until completing the 10 swfs, I am using something thus for each swf "tran1_mc.loadMovie(_root.i11)", in the HTML if I to place 10 swfs it pulls normal, all certainty so far, but if in my HTML to say only it to pull 3 swfs, it pulls these 3 swfs and the remaining portion is blank, what necessary to make it is when to finish to show to this 3º swf it comes back to the first one, somebody has an idea of as I can make this?
What's More Accurate? GetTimer Or On EnterFrame?
Hello everyone,
I’m creating a video editor in flash. In the timeline I use getTimer and setInterval to measure the time. My question is: is this accurate enough. If not what should I use.
I tested onEnterFrame and setInterval together, onEnterFrame is taking longer to get to 5 seconds.
Maxgrafx
Preloader - Works But Not Accurate...
Hello, I made the preloader from the tutorial on this site...
The one that shows a bar and a percent of what is loaded...
It works but the bar will be about half way across when it says it is at like 80%...
Is that just processor lag or something?
Here is the site...
http://www.videolinktechnologies.com/new/
Thanks...
100% Accurate Countdown Timer?
Hi,
BACKGROUND
I need to make a countdown timer in Flash that will countdown in seconds to the next whole hour and then will reset and countdown to the following next hour
The timer needs to be 100% accurate.
QUESTION
Is it possible to create a countdown timer in actionscript which will be perfectly accurate - ie. will always be identical when compared with actual rea-life time, irrespective of the hardware, processing of applications done on a client machine?
If this is not possible, is it possible to include in the code a detection of when the timer becomes inaccurate and then further code to get it back on track to correct the inaccuracy?
Any code examples/links to tutorials regarding above issues would be greatly appreciated.
Thanks
Accurate Timing Function
I'm writing a function that basically imitates the Timer Class in AS3 but minimizing the discrepancy between intervals (see here). The problem is that the minimal discrepancies there are with this function have a cumulative effect and I need the timer to stay as close to on the beat as possible rather than getting slightly further away each time.
So i need a way to reset the timer to where it should be if there are any discrepancies. The basic code is:
Code:
function timer(i:Number, n:Number) {
var timeNow:Number;
var timeLast:Number = 0;
var c:Number = 0;
root.addEventListener(Event.ENTER_FRAME, gen);
function gen(e:Event):void {
timeNow = getTimer() - timeLast;
if (timeNow >= i) {
timeLast = getTimer();
c += 1;
trace(c+", timeNow: "+timeNow);
if (c == n) {
root.removeEventListener(Event.ENTER_FRAME, gen);
}
}
}
}
timer(1000, 0);
I've tried a couple of different ways of adjusting the next interval if the timer runs slow to set it back on track but i can't seem to get anything to work.
Any help much appreciated
To Pull Only The Accurate Amount.
I am with a small problem, is the following one, I have my main file that this calling 10 swfs external, example in frame 1 calls one swf, in frame 150 calls another one, in frame 230 calls another one and thus it goes until completing the 10 swfs, I am using something thus for each swf "tran1_mc.loadMovie(_root.i11)", in the HTML if I to place 10 swfs it pulls normal, all certainty so far, but if in my HTML to say only it to pull 3 swfs, it pulls these 3 swfs and the remaining portion is blank, what necessary to make it is when to finish to show to this 3º swf it comes back to the first one, somebody has an idea of as I can make this?
100% Accurate Countdown Timer?
Hi,
BACKGROUND
I need to make a countdown timer in Flash that will countdown in seconds to the next whole hour and then will reset and countdown to the following next hour
The timer needs to be 100% accurate.
QUESTION
Is it possible to create a countdown timer in actionscript which will be perfectly accurate - ie. will always be identical when compared with actual rea-life time, irrespective of the hardware, processing of applications done on a client machine?
If this is not possible, is it possible to include in the code a detection of when the timer becomes inaccurate and then further code to get it back on track to correct the inaccuracy?
Any code examples/links to tutorials regarding above issues would be greatly appreciated.
Thanks
Accurate Collision Detection
Last edited by Nutrox : 2004-12-01 at 13:21.
Hi guys.
This is another one of those "could I be doing this better" kinda questions
I need to work out accurate collision detection between objects in a 2D game. I am using hitTest() to check for collision between objects but this has it's limits and problems.
The main problem is that the objects are moving and they could be over-lapping each other when hitTest() returns true, and I need to avoid that over-lapping.
The way I'm doing this at the moment is to check for a collision using hitTest() and then running a loop that "reverses" the objects position until hitTest() returns false (at which point the two objects will appear to be touching and not on top of each aother).
Here's a simple example of how this is working... mcA is moving from left to right.. mcB is static.
ActionScript Code:
this.onEnterFrame = function():Void
{
mcA._x += 10;
if(mcA.hitTest(mcB))
{
while(mcA.hitTest(mcB))
{
mcA._x -= 0.5; // shift mcA until no hitTest is found
}
}
}
The problem is I'm a bit worried that doing things that way will eat up CPU if there are quite a few objects on screen. Each object will be able to move in any direction so there will be a lot of checking to do.
Does anyone know of any other techniques/methods that could be used for accurate detection?
Cheers.
Si ++
To Pull Only The Accurate Amount.
I am with a small problem, is the following one, I have my main file that this calling 10 swfs external, example in frame 1 calls one swf, in frame 150 calls another one, in frame 230 calls another one and thus it goes until completing the 10 swfs, I am using something thus for each swf "tran1_mc.loadMovie(_root.i11)", in the HTML if I to place 10 swfs it pulls normal, all certainty so far, but if in my HTML to say only it to pull 3 swfs, it pulls these 3 swfs and the remaining portion is blank, what necessary to make it is when to finish to show to this 3º swf it comes back to the first one, somebody has an idea of as I can make this?
|