ActionScript 3.0 :: Math.floor Vs Bit Shifting Vs Int
Aug 17, 2009
I just ran some tests on round numbers.In preparation for getting max performance from AS3, I want to test as many areas as possible.All I did was generate a rounded random number a million times per frame, and record the time step in milliseconds.[code]Now the strangest part is having a non rounded random number generated a million times per frame netted an average time of 195 milliseconds, faster than using int as a random number. It must simply be that because Math.random isn't returning an integer, some form of conversion of taking place for your variable to be an integer.
Incidentally, using a Number instead of integer for the looping variable decreased performance minimally, just a few milliseconds.So simply having your variable as an integer, and using no rounding at all produces the fastest results if you want a round number.Remember though, there are many other areas in Flash to dramatically increase performance. Being that we're talking about a million iterations per frame, the difference in performance is not exactly dramatic here. One is not even twice as fast as another, over a million iterations.
View 5 Replies
Similar Posts:
Mar 7, 2011
Here is the problem:
var p:int = 0;
var n:Number = 0;
n = 32.999999999999999;
p = Math.floor(n);
trace(p); // returns 33
n = 32.11111111111111;
p = Math.floor(n);
trace(p); // returns 32
I would expect both of these to return 32. I have searched, and it seems this is an unreported bug in AS3. Or ... am I doing something wrong?
View 4 Replies
Sep 26, 2005
Wat is the diffrence between these two?
View 2 Replies
Apr 16, 2007
For some reason my math.floor function is not working (trace yields "undefined")..[code]
View 2 Replies
Jan 28, 2008
project width is 500
tile_width=25;
map_collumns=Stage.width/tile_width
trace(map_collumns)
Sometimes I get a decimal return. Then, when I close it,and run it again, it shows the correct answer.
View 10 Replies
Mar 12, 2008
I want to round a whole number down to the nearest whole 10th. Like 52, becomes 50. Or 49, becomes 40. Or 2005, becomes 2000. Does that make sense? I imagine it has a math.floor approach, but I can not figure it out.
View 5 Replies
Mar 31, 2011
I am trying to create a simple floor plan that highlights where the computers are on the floor.
1. Each computer has a name for e.g. Comp1, Comp2, Comp3 etc.
2. The computer names are in a list on the left hand side.
3. On the right hand side is the simple floor plan with computer images (or clipart)
This is what is expected:
1. As the mouse is mover over the item on the list, the computer associated with it must light up (or highlighted) For e.g. when the mouse is over Comp1 in the list then computer1 image (or clipart) on the floor plan must light up
2. When the mouse is over a computer on the floor plan, then the associated computer name in the list must light up For e.g. when the mouse is over computer2 image (or clipart), then Comp2 in the list must light up. I was trying to get some ideas from [URL]. I was able to make the image for a computer. It doesn't go far enough to tell me how to accomplish the above. Using Excel, I did this nearly five years back, by putting the clipart in specific cells and hyperlinking them. Now we want to make it available on the web.
View 5 Replies
Feb 16, 2009
I have a code in which I have to use Math.round if a certain value is for example 3.67 (67 is higher than 50) and Math.ceil if a value is for example 3.23 (23 is lower than 50). What can I do to make flash calculate if what after the dot �.� in 3.23 (for example) is higher than 50?
View 2 Replies
Jan 15, 2011
is there any lib or api out to deal with this ? EVEN, if there is any resource , article from another language c++ , c , .. i just didn't have enough time to test lot of ways
If you search interactive floors , or interactive floor projection you can find some companies who provide such a thing
View 2 Replies
Apr 25, 2011
I am currently building a commercial website, and am stuck on the functionality of a 'Featured Businesses' animated graphic. The functionality is there, it works, but the problem is, I can't figure out a proper way to make it so that when one button is pressed (that is behind the others on the timeframe), how can I make it so that all the frames/layers (which contain the other buttons) go behind whatever button is activated?
As I said, it works, the problem is that all but the last button (which is the top layer) are obscured from view by the other buttons/MC's that are on top of it as far as the timeline is concerned.!
I tried messing around with the objectdestroy function, but this is my first foray back into ActionScripting since I scripted my last 2D platformer way back in 2005 when I was using Flash MX and before Adobe took control. So I'm rusty.
The link below should contain the .swf of the functional graphic. As you can see it works, but the top buttons are behind the others, so you can't see their animation fully.=
View 1 Replies
Aug 10, 2009
I'm not sure if this is directly hardware related or not. I've just started playing around with papervision 3d and I threw together this map floor and test sprite to see how it would look. The problem is, whenever I have a large portion or the map in my viewport, it lags. I was just wondering if maybe:
a) My code is horrid
b) My computer is a piece
c) Papervision3D is just bad for 3D
I mean the concept is simple, there's nothing fancy going on and I'm only using planes. Maybe it's because I'm using 25x25 of them? Is there a better path to use 3D than paper3d? Anyways, here's the code.
ActionScript Code:
//import files
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
[Code] .....
View 2 Replies
Feb 8, 2010
I am designing a character to move right and left but the character is not recognising the floor movieclip and is falling straight threw the floor.I have attached a zip file with the flash document sample and associated Actionscript file.
View 2 Replies
Feb 19, 2007
im currently workin on a game in my spare time and have come across a few problems. I've gone back to basics to figure out a redesign of my code using functions.
Here's my initial problem:
I have a button, which when pressed will shift a sprite 100px to the right. I wanted it so that everytime i pressed the button, the sprite moved a further 100px from it's stopped location. So basically if it's moving and you push the button again, it'll do nothing. It has to be stationary in order to move. At the moment my code shifts the sprite when the button is pressed, but it just keeps moving forever and doesn't stop
[Code]....
View 2 Replies
Mar 2, 2009
I have an odd situation where the static text each within a mc for a menu are shifting slightly up and down despite having the exact same rounded x/y values throughout on the timeline in the properties box. There are a few frames on the timeline where they are contained within another movieclip to fade them in, and when I zoom in and make sure they line up exactly, they are fine, but when I play the movie back at various magnifications within the authoring environment and as an exported swf, they randomly shift slightly. Sometimes they randomly shift, and other times at the same magnification they don't at all when replayed back again. It's making me pull my hair out and grind my teeth because I don't know if I am dealing with a known bug or (more likely) my ignorance. I know there is a better way of doing this all with action script, but honestly I am not there yet by a long shot, unless someone could direct me to a proper tutorial.
View 5 Replies
Dec 30, 2009
I am new to the forum, I have used Flash MX 2004 for quite a while and had never had this problem, recently I gave my site a "facelift" in CS4 and I got it exactly how I wanted it, I exported the swf file and saved the flash file. That was a few days ago, Today I wanted to add a new piece to my portfolio so I opened the same exact file today and everything had shifted! SOOOO FRUSTRATING as I felt I had finally achieved what I wanted to. This is the one I was really happy with:
[Code]...
View 3 Replies
Apr 29, 2010
Is it possible to create interactive floor plans in flash CS4? Are there any tutorials out there to do this?
View 1 Replies
May 17, 2010
I WAS WONDERING HOW TO MAKE AN INTERACTIVE PICTURE VIEWER IN fLASH LIKE WHAT APPLE HAS IN LEOPARD AND SNOW LEOPARD. FOR EXAMPLE, WHEN THE PICTURE IS IN FRONT OF YOU AND YOU CAN SEE OTHER PICTURES BESIDE IT BUT THEY ARE FURTHER AWAY AND YOU CAN SEE THE REFLECTION ON THE FLOOR OF IT IS THIS A POSSIBILITY IN fLASH?
View 2 Replies
Oct 25, 2010
We have floor plans of a building in the DB in PNG format. We am using arcGIS flex api. We want to build something like [URL] How can we load my building floor plan onto the arcGIS flex map.
View 1 Replies
Mar 28, 2004
im making a game but im already having trouble with the first code, i just want the user to fall when he is not touching a floor....i put this code on the user:
[AS]onClipEvent(enterFrame){
if(falling=true){
this._y=this._y+5}[code]....
theres is no errors but it doesnt stop when it hits the floor
View 4 Replies
Jan 16, 2004
So here is a piece of code that I have seen used a lot but don't really quite understand:
myVar = Math.min(Math.max(myVar, this.min), this.max);
or some variation thereof. I understand that the function first finds the maximum value of two values then turns around and uses that to find the minimum between two values.why this is done? And how do you know when to use it?
View 3 Replies
Jan 16, 2004
So here is a piece of code that I have seen used a lot but don't really quite understand:[code]or some variation thereof. I understand that the function first finds the maximum value of two values then turns around and uses that to find the minimum between two values.And how do you know when to use it?
View 3 Replies
Nov 10, 2008
I've been trying to piece together a way to have an image with a flag wave fade in as soon as the movie loads. Once the image is faded in almost all the way, I want the waving to slow to a stop so at the end, it's a static image. I've gotten most of this accomplished, however, once the flag wave slows and stops, the entire image shifts up and to the right. I'm sure it has something to do with some displacement variable, but since I'm no coder I can't seem to figure out how to stop this.[code]...
View 1 Replies
Jul 27, 2010
I am dynamically creating a bunch of buttons which each toggle their variable on and off, causing corresponding graphics to hide.I also want to have a toggle All on and off button that affects all the variables.I can't seem to get my head around the best approach to turning all the individual variables on/off when I don't really know what those variables will be yet, cause it will depend on how each version of this gets set up.
View 2 Replies
Jul 4, 2009
I'm creating a custom video player where the user can select to play the same video at different speeds (100%, 75%, and 50%).We have rendered 3 different MP4 files,one for each speed, and then there is a mechanism in the video player to load each video as the user demands it.It works fine so far, except that when a new video loads,it begins to play from the beginning, not at the point where the previous video left off (which is crucial).
I thought it would be as simple as using either ns.play("videoname", videotime) or using a ns.seek(videotime), but in ether case,the new video still will only play from the beginning.Here is the code, which includes some calculation for adjust the time depending on the shift from 100%, 75%, and 50%.
function switchSpeedVideo() {
var currentTime:Number = ns.time;
output.text = currentTime.toString(); // outputs correctly[code].....
What is missing here?Currently, I am using HTTP connection("HTTP Pseudo Streaming" with Wowza on SimpleCDN).Does this require RTMP?
View 3 Replies
Sep 21, 2009
We have noticed Fonts shift down in our layouts. Our files are very messed up. One particular font that is doing this is TheMix. Anyone else have this happening? The same file opens and displays just fine under Leopard.
View 2 Replies
Jun 30, 2010
how to set up 2 pre selected colors to tween a gradient to instead of "random" ones. My Goal would be to use this class as a dynamic background creater and i would like to have different gradient backgrounds on different pages.
View 1 Replies
May 18, 2010
I have a simple xml driven navigation comprising of 8 items. How I could move the items up if clicked e.g if nav item 3 is clicked, 3,4,5,6,7 and 8 move upwards (so that 3 is at a Y position of 0), and nav item 1 and 2 drop to bottom of nav list?
3
4
5
6
7
8
1
2
View 9 Replies
Oct 18, 2006
Is there a way of scrolling (shifting) a movie clip so that a part of it continuously shifts to the other side, i.e. when you scroll the movie clip to the left, the portion that scrolled out appears on the right (like a picture on a rotating drum). Of course in AS 2.0
View 7 Replies
Jan 19, 2010
What would be a good way to create a grid of images in which one can be dragged to a new position and the other images will shift to make room for the image dragged? Looking at making a little program that will reorder an XML file by visually dragging the items to where I want them.
View 0 Replies
Oct 29, 2010
I'm having some problems porting a palette shifted animation system from J2ME to Flash. The system is used within a game that construct characters from separate body parts for e.g. head, left arm, legs, eyes, mouth etc. These can then be tinted and animated. Each of these body parts is coloured using a look up table. There is the original palette, then there are 18 other palettes that can be used to tint the image. This way you can configure different looking characters without having hundreds of different images. Each palette has 398 colours, there are 18 different palettes in total.
Each body part contains a small amount of colours, usually around 10-20. Colour A1, Colour B1 etc... Then the body part can be tinted using another set of colours, for eg Colour A3, B3, C3 etc.. It's simply a 2D array. (I have screenshots that help explain if needed) Now I've been trying to use PaletteMap, without success. I believe it uses a full colour palette (i.e. 255 vals per colour), and can't simply change colour A1 to colour A3 etc.
I also tried threshold, but that doesn't seem to be fit for purpose. getPixel / setPixel is way too slow for my purpose. It needs to be pretty fast as each body part is animated. I have a lot of flash programming experience, but never at such a low level! I might have been using paletteMap / threshold incorrectly, but the adobe docs leave a lot to be desired!
View 0 Replies