| Ultrashock Forums
• ActionScript Tips Thread |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
| <12 | Page 2 of 2 |
17 Creative Assets
|
2006-12-13
#41 |
||
|
038 - Math and Bits
Last edited by Nutrox : 2006-12-24 at 05:08.
If you have been paying attention to this thread then you should know that you can quickly floor a number with bit-shifting ( 12.34 >> 0 = 12 ). You can also get the same performance increase if you use bit-shifting for multiplication and division. This will not work for all values though, you can only multiply and divide values by 2, 4, 8, 16, 32, and so on. Also, the result will be rounded down (floored). However, if you are working with grids or tile based games then this can come in very handy. To multiply a value you left-shift, and to divide a value you right-shift. First of all, take a look at the following trace values: ActionScript Code:
ActionScript Code:
ActionScript Code:
ActionScript Code:
Here are a few more examples: ActionScript Code:
|
|
2006-12-24
#42 |
||
|
039 - Having private constructors
Last edited by Codemonkey : 2006-12-27 at 06:54.
Sometimes you would want to make a class constructor private when:
|
17 Creative Assets
|
2007-02-26
#43 |
||
|
040 - [AS3] Reversing the Display List
Reversing the display order of objects is extremely easy in AS3. The function: ActionScript Code:
ActionScript Code:
|
17 Creative Assets
|
2007-02-27
#44 |
||
|
041 - Odd or Even
Last edited by Nutrox : 2007-02-27 at 21:53.
A quick 'n' simple way to find out if a number is odd or even is to use the modulo operator ( % ). ActionScript Code:
|
17 Creative Assets
|
2007-09-14
#45 |
||
|
042 - Radian/Degrees Optimisation
In tip 035-Trigonometry I showed how to convert radians to degrees and vise-versa. I needed to get those conversions happening a lot quicker so I tried a few things out and ended up with the following: Degrees to Radians (original) radians = ( degrees / 180 ) * Math.PI Degrees to Radians (new) radians = degrees * 0.01745329251994 The (new) version is about 12 times faster than the (original) version. Radians to Degrees (original) degrees = ( radians / Math.PI ) * 180 Radians to Degrees (new) degrees = radians * 57.29577951308232 Again, the (new) version is about 12 times faster than the (original) version. I don't think it is possible to get the conversions happening any quicker than that, even using lookup tables would be slower, but if anyone does know of a quicker way to do the conversions please let us know.
|
|
2007-09-15
#46 |
||
|
043 - Radian/Degrees Optimisation followup
This approach for math operation works well in general and is akin to the lookup table approach, where you avoid unneeded repetition. For clarity, you may want to define constants for these precalculated values so you and other people remember how you got this 'magic' value. ActionScript Code:
ActionScript Code:
|
| <12 | Page 2 of 2 |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|


17 Creative Assets
Linear Mode