How to optimize the performance of this code?

I have two clips on a flash project. One of them is fixed and the other can be moved with the arrow keys of the keyboard. The two clips have irregular shapes, so HitTestObject and HitTestPoint does not work very well. I have a function that detects the collision of two clips using bitmap. I wanted to update the position of the Movie clip mobile so I put the function of collision detection under the ENTER_FRAME event listener code. It works fine, but when I add many fixed film clips (about 10 clips fixed in an image), the game (.swf file) becomes slower and slows down the performance of the PC. I thought that my collision detection function has a negative effect on the performance of the PC, so I used the class on this page: https://forums.adobe.com/thread/873737
but the same thing happens.

You told me how to do to speed up execution of my codes?

Here's the part of my code:

stage.addEventListener (Event.ENTER_FRAME, myOnEnterFrame);

function myOnEnterFrame(event:Event):void

{

If (doThisFn) / / doThisFn is a variable to allow or prevent the kind of mobile film clip moved with arrow keys

{

If (left & &! right) {}

Player.x = speed;

Player.rotation = player.rotation - speed;

}

If (right & &! left) {}

Player.x += speed;

Player.rotation = player.rotation + speed;

}

If (up & &! down) {}

Player.y = speed;

}

If (down & &! up) {}

Player.y += speed;

}

The clips of film sets are wall1, wall2, wall3, wall4,... and so on
the following code checks to see how many walls exist on each image and pushes them in table wallA

for (var i: int = 0; i < 1000; i ++) / / you can put up to 1000 object of wall in the table wallA

{

If (this ['wall' + i]) / / if the wall object exists, push it into the table wallA

{

wallA.push (this, ['wall' + i]);

}

}

for (i = 0; i < wallA.length; i ++)

{

If ( h.hitF (player, wallA [i]) | gameOverTest) / / this code checks whether or not the player (the mobile clip) hit the walls

{

trace ("second try");

gameOver.visible = true;

doThisFn = false;

}

}

I think the following codes are easy to turn and run. I think that the performance problem is due to previous codes.


If (player.hitTestObject (door))

{

Win.Visible = true;

doThisFn = false;

}

If (key) / / if there is a key on chassis

{

If (player.hitTestObject (key))

{

Key.Visible = false;

switch (currentFrame)

{

case 4:

wallA [0] .visible = false;

.x wallA [0] = 50000;

break;

case 5:

wall14. Play();

wall8.x = 430;

break;

}

}

}

}

}

It's a simple question that doesn't usually have a simple answer.

Here is an excerpt of a book (Flash game development: in a Social, Mobile and 3D world) I wrote.

Optimization techniques

Unfortunately, I don't know any way completely satisfactory to organize this information. In what follows, I discuss memory management first with sub-themes listed in alphabetical order. Then I discuss the management of CPU/GPU with subheadings listed in alphabetical order.

This may sound logical, but at least, there are two problems with this organization.

1. I don't think it's the most useful way to organize this information.

2. memory management affects the CPU/GPU use, so that everything in the section of memory management can also be listed in the section CPU/GPU.

In any case, I'll also list information in two other ways, from the easiest to the most difficult to implement and more for much less.

Two of these later inscriptions are subjective and dependent on experience developer and capabilities, as well as environmental test and the test situation. I very much doubt there would be a consensus on the order of these lists.  However, I think that they are still valid.

Easier to the more difficult to implement

1. do not use the filters.

2. always use the reverse for loops and avoid loops and avoid while loops.

3. explicitly stop timers for their loan for gc (garbage collection).

4. use the weak event listeners and remove headphones.

5. strictly type variable when possible.

6. explicitly disable interactivity mouse when interactivity smile not necessary.

7. replace dispatchEvents with callback functions whenever possible.

8 it would be gc stop sounds for the sounds and SoundChannels.

9. use the DisplayObject most basic need.

10. always use cacheAsBitmap and cacheAsBitmapMatrix with air applications (i.e., mobile).

11. reuse of objects when possible.

12 Event.ENTER_FRAME loops: use different listeners and different listener functions applied to DisplayObjects as little as possible.

13. the pool instead of creating objects and gc objects ' ing.

14. use partial blitting.

15. use step blitting.

16 use Stage3D

Biggest advantage less

  1. Use the blitting Stadium (if there is enough memory system).
  2. Use Stage3D.
  3. Use partial blitting.
  4. Use cacheAsBitmap and cacheAsBitmapMatrix with mobile devices.
  5. Disable explicitly interactivity mouse when interactivity smile not necessary.
  6. Do not use filters.
  7. Use the most basic necessary DisplayObject.
  8. Reuse objects whenever possible.
  9. Event.ENTER_FRAME loops: use different listeners and different listener functions applied to DisplayObjects as little as possible.
  10. Use reverse for loops and avoid the do loops and while loops.
  11. The pool instead of creating objects and gc'ing.
  12. Strictly, type variable when possible.
  13. Use weak event listeners and remove headphones.
  14. Replace dispatchEvents by the callback functions whenever possible.
  15. Explicitly stop timers on loan for the gc.

16 stop sounds for the sounds and SoundChannels be gc would be.

Tags: Adobe Animate

Similar Questions

  • How to optimize the performance of this query SQL

    Hello

    I need to find the age for each day, but I need for all previous dates in a single query. So I used the following query:

    Select trunc (sysdate) - level + 1 DATE

    trunc (sysdate) - level + 1 - created_date AGE

    elements

    connect by trunc (sysdate) - level + 1 - created_date > 0

    I get output (FOR the DATE and AGE) that is fine and correct:

    DATE AGE           

    --------- ----------

    6 JULY 15 22

    5 JULY 15 21

    4 JULY 15 20

    3 JULY 15 19

    2 JULY 15 18

    JULY 1, 15 17

    JUNE 30, 15 16

    JUNE 29, 15 15

    JUNE 28, 15 14

    JUNE 27, 15 13

    JUNE 26, 15 12

    25 JUNE 15 11

    24 JUNE 15 10

    Now I need to calculate the average age for each day and I added the average in the following query:

    Select trunc (sysdate) - level + 1 DATE .

    AVG (trunc (sysdate) - level + 1 - created_date) AVERAGE_AGE

    elements

    connect by trunc (sysdate) - level + 1 - created_date > 0

    Group of trunc (sysdate) - level + 1


    This query is correct? When I add the aggregate (avg) function to this query, it takes 1 hour to retrieve the data. When I remove the average request function that gives the result in 2 seconds? What is the solution to calculate the average without affecting performance? Help, please

    Maybe you are looking for something like this...

    SQL > ed
    A written file afiedt.buf

    1 with t (point, created_date) :)
    2 Select 1, date '' 2015-06-24 from all the double union
    3 select 2, date ' 2015-06-29 the Union double all the
    4 Select 3, date ' 2015-06-17' of the double
    5        )
    6  --
    7. end of test data
    8  --
    9. Select item
    10, trunc (sysdate) - level + 1 as dt
    11, trunc (sysdate) - level + 1-created_date age
    12, round (avg (trunc (sysdate) - level + 1 - created_date) on (trunc (sysdate) partition - level + 1), 2) as avg_in_day
    13 t
    14 connect by level<=>
    15-point point = prior
    sys_guid() 16 and prior is not null
    17 * order by 1.2
    SQL > /.
    POINT DT AGE AVG_IN_DAY
    ---------- ----------- ---------- ----------
    1 JUNE 24, 2015 0 3.5
    1 25 JUNE 2015 1 4.5
    1 26 JUNE 2015 2 5.5
    1 27 JUNE 2015 3 6.5
    1 28 JUNE 2015 4 7.5
    1 29 JUNE 2015 5 5.67


    1 30 JUNE 2015 6 6.67
    1 1 JULY 2015 7 7.67
    1-2 JULY 2015 8 8.67
    1-3 JULY 2015 9 9.67
    1 TO 4 JULY 2015 10 10.67
    1 5 JULY 2015 11 11.67
    1 6 JULY 2015 12 12.67
    2 JUNE 29, 2015 5.67 0
    2 30 JUNE 2015 1 6.67
    2 1 JULY 2015 2 7,67
    2 2 JULY 2015 3 8.67
    2-3 JULY 2015 4 9.67
    2-4 JULY 2015 5 10.67
    2-5 JULY 2015 6 11.67
    2-6 JULY 2015 7 12.67
    3 JUNE 17, 2015 0 0
    3 18 JUNE 2015 1 1
    3 19 JUNE 2015 2 2
    3 20 JUNE 2015 3 3
    3 21 JUNE 2015 4 4
    3 22 JUNE 2015 5 5
    3 23 JUNE 2015 6 6
    3 24 JUNE 2015 7 3.5
    3 25 JUNE 2015 8 4.5
    3 26 JUNE 2015 9 5.5
    3 27 JUNE 2015 10 6.5
    3 28 JUNE 2015 11 7.5
    3 29 JUNE 2015 12 5.67
    3 30 JUNE 2015 13 6.67
    3 1 JULY 2015 14 7.67
    3 2 JULY 2015 15 8.67
    3 3 JULY 2015 16 9.67
    3-4 JULY 2015 17 10.67
    3-5 JULY 2015 18 11.67
    3 6 JULY 2015 19 12.67

    41 selected lines.

  • How to improve the performance of this loop?

    Hello

    I have this code below performs a loop on both issues, which compares the files in them. The performance is bad. Can someone tell me how to accomplish this task in an effective way?
    Please note that both folders can be on the network and most often contains 5000 + files.
    for (int i = 0; i < sourceList.length; i++) {
    for (int j = 0; j < targetList.length; j++) {
        if (sourceList.getName().equalsIgnoreCase(targetList[j].getName())) {
    if (sourceList[i].lastModified() > targetList[j].lastModified())
    {
    newInSourceList.add(sourceList[i]); //ArrayList 1
    }
    else if(sourceList[i].lastModified() < targetList[j].lastModified())
    {
    newInTargetList.add(targetList[j]); //ArrayList 2
    }
    }
    }
    }


    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    This minute is spent for the most part between the two points I mentioned below (Point A & B).

    I guess time will especially isFile() calls. That should make a stat() system call, which calls the network file server.

    If you can target Java 7 and greater, you can use the new java.nio.file and BasicFileAttributes. Allows you to extract the data to stat() each file in a single call, so that lastModified() and isFile() must separate calls to the file server. It will not yet be fast like lightning, but maybe almost 2 x faster - I think that all other treatments are overshadowed by calls on the network.

        // Read file attributes to a list (or use a Map if you prefer)
        String files[] = new File(Directory).list();
        BasicFileAttributes attributes[] = new BasicFileAttributes[files.length];
        for (int n = 0; n < files.length; n++)
            attributes[n] = Files.readAttributes(Paths.get(directory, files[n]), BasicFileAttributes.class);
    
        // Now you can use
        attributes[n].lastModifiedTime()
        attributes[n].isRegularFile()
        // etc without each call hitting the file server.
    
  • How do I optimize the performance of windows 7 with freeware tool or tool?

    How do I optimize the performance of windows 7 with freeware tool or tool?

    Hello

    As Frederik advised, saving No. tune-up, not so-called Optimizer program, no registry cleaners should be used.

    See if this helps you improve performance.

    Search for malicious software with the FREE version of this program.

    This is the right link to download included.

    And does not accept the option "Pay for the version" trial installation

    Download, install, update and scan your system with the free version of Malwarebytes AntiMalware:

    http://www.Malwarebytes.org/products/malwarebytes_free

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    You can clean your hard drive using these two methods.

    "Delete files using Disk Cleanup"

    http://Windows.Microsoft.com/en-us/Windows/delete-files-using-disk-cleanup#delete-files-using-disk-cleanup=Windows-7

    Using the free CCleaner program:

    http://www.Piriform.com/CCleaner

    In NO case use the registry cleaning Option in CCleaner

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    And it is not recommended to use a register or a program of cleaning/TuneUP/utilities they can do more harm to your any good operating system that they claim to be able to do.

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    Make sure you have the latest updated drivers:

    Access the site on your computer or equipment manufacturing > Driver and Software Support Section > search your computer or hardware model number > then your operating system > locate the correct drivers > download and install.

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    What are the other steps, which does not include some of the above:

    "Optimize Windows for better performance.

    http://Windows.Microsoft.com/en-us/Windows/optimize-Windows-better-performance#optimize-Windows-better-performance=Windows-7

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    It would be a good idea also run the System File Checker tool to check that everything is correct in the system files.

    "How to use the System File Checker tool to fix the files on system missing or corrupted on Windows Vista or Windows 7"

    http://support.Microsoft.com/kb/929833

    Use the (SFC.exe) System File Checker tool to determine which file is causing the problem and then replace the file. To do this, follow these steps:

    1. Open an elevated command prompt. To do this, click Start, click principally made programs, Accessories, right-click guest, and then click run as administrator. If you are prompted for an administrator password or a confirmation, type the password, or click allow.
    2. Type the following command and press ENTER:
      sfc/scannow

      The sfc/scannow command analyzes all protected system files and replaces incorrect versions with appropriate Microsoft versions.

    See you soon.

  • Optimize the performance of Windows 8.1

    Hi all

    I bought a HP Envy dv6 (including Windows 8) in November 2012.

    For all those people who have good experiences with Windows 8.1... I was wondering what software you used to optimize performance?

    In the past I had good experiences with...

    Avast

    Advanced System Care 6

    CCleaner

    IObit Malware Fighter

    Driver boost

    However, in Windows 8, it seems that some of them were because of issues with apps from metro.  I had to reset my computer to factory settings countless times because for some reason any my metro apps can not maintain an INTERNET CONNECTION.

    You guys are using any antivirus software or registry/maintenance software to optimize the performance of your PC which has not caused any problems?  Leave the windows firewall "on" your best option for protection?

    Chrome or Internet Explorer?

    Make adjustments to settings PC (like the game "never notify" in the settings of the user account, etc.)?

    What are some software 'must have' that you found useful?

    Thanks in advance!

    Hello!

    Thanks for posting in the forum to Support HP and you thank for your trust in HP!

    I'll try to answer some of your questions:

    For all those people who have good experiences with Windows 8.1... I was wondering what software you used to optimize performance?

    No, it works well on its own. Less you hit, the better. 3 party registry cleaners and optimizers should be used with caution by people with advance knowledge on the subject. More 3rd party (most, not all) optimizers are causing problems more than fix. Remove unnecessary programs, defrag automatically or auto (so HARD, not so SSD drive), run Disk Clean up, clear Temp folder.

    Avast

    Advanced System Care 6

    CCleaner

    IObit Malware Fighter

    Driver boost

    These I wouldn't use one of them.

    You guys are using any antivirus software or registry/maintenance software to optimize the performance of your PC which has not caused any problems?  Leave the windows firewall "on" your best option for protection?

    Light antivirus is ESET and clean of Windows Defender. Windows Firewall (firewall) is essential (critical) part of any system, computer security, network, so it must be turned on. To do this, * no * slow down your computer or your * network * traffic.

    Being without firewall you leave at the open to pirate computer/malware attacks and risk huge data.

    Antivirus software is also a kind of essential program to protect against known and unknown malware attacks. Windows Defender is integrated in Windows 8/8.1 if you don't like it, you can try ESET NOD32, Norton Antivirus...

    Chrome or Internet Explorer?

    They are both very light when it comes to performance. I personally chose IE 10 (my favorite - in win 7 and 8) and IE11. But that's my opinion. Use what suits you best. IE is very safe and stable in the latest versions of Windows. That is to say, I prefer because it is the 1st part, made from Microsoft and works.

    Make adjustments to settings PC (like the game "never notify" in the settings of the user account, etc.)?

    User account control is also very good part of the guarantee. In fact, it helps the principle of "least privilege" security and helps your programs to run with the least amount of law they can. I recommend that you use the value default level3 or the more level '4 always notify when. User account control can help you prevent malicious attacks / viruses / threats.

    What are some software 'must have' that you found useful?

    In my opinion, there is no such thing as software should be - everyone installs and uses what they need. Statistics show that most people (98% or more) use Microsoft Office. Many have some archivers zip/rar as 7-zip, video software like VideoLAN, etc... It depends on what you need. Antivirus software...

    Visit www.microsoft.com/protect for more information on keeping computer secure and shaped

    If it please let me know if I can help you further and do not hesitate to ask for assistance if you have problems.

    Please, click on the star of white LAURELS (left). This way you'll testify for advice or help you have received.  If your problem has been resolved - click on the appropriate button and accept the solution. ***

  • How to improve the performance of the import

    I'm converting a database of its current WE8ISO88591 character set AL32UTF8
    I use NLS_LENGTH_SEMANTICS to TANK so I don't have to increase the length of the column.

    I followed the instructions in the Oracle:
    144808.1
    313175.1

    Except import that takes too long.

    I took a full database export WE8ISO8859p1 and now its importation in AL32UTF8.

    It is always difficult to prove slow source; but I think it has to do something with NLS_LENGTH_SEMANTICS. On the same
    Server; If the new database was in WE8ISO8859P1, a 5 million row table import took 2 hours; but in Al32UTF8 with NLS_LENGTH_SEMANTICS it takes 1 day!

    No idea how to improve the performance of the import.

    DOUBLE WIRE!

    Please, don't post duplicate discussions.

    Mark this thread ANSWER and continue to use your original thread where you are already helped.

    You have NOT given the info that has been ask in your other thread.
    Re: NLS_LENGTH_SEMANTICS = CHAR import is too slow

  • I think that my computer might work better with less buffering, how to optimize its performance?

    I think that my computer might work better with less buffering, how to optimize its performance?

    How much RAM you have.   If it's 4 GB or less, you may need to upgrade.   8 GB would be excellent although Apple suggests much less.

  • What is the best way to improve the performance of this all-in-one PC?

    What is the best way to improve the performance of this all-in-one PC?

    Thanks in advance.

    David Barrett.

    Here are a few methods:

    • Run msconfig.exe, and then uncheck the startup tasks that you don't need. No matter what you disable, Windows always starts.
    • Use a light virus scanner, for example Microsoft Security Essentials.
    • Replace your magnetic drive with a Solid State Disk (SSD)
  • How to restore the settings of "color code" default colors in DW CS5?

    Greetings,

    How to restore the settings of "color code" default colors in DW CS5?

    Thank you!

    Try http://forums.adobe.com/message/2634995

    See also

    http://forums.Adobe.com/thread/494812?TSTART=0

  • How to optimize the query with a join of virtual tables

    I'm working on a query that is get the data of virtual tables 2 and b
    one is formed by the Union, all say 4 queries and b is formed by the Union, all say 3 queries
    then these two virtual tables and b are joined on a column common and data are extracted from their part.
    Problem is that there is about 1 minutes each in the two virtual tables has and b. If individual a and b queries virtual takes about 5 seconds to retrieve data
    but the join on column takes about 25 seconds to retrieve data.
    Can someone guide me how to optimize the recovery of joining 2 virtual tables having large data

    Thank you

    Please read these:

    When your query takes too long
    When your query takes too long...

    How to post a SQL tuning request
    HOW to: Validate a query of SQL statement tuning - model showing

  • How to optimize the speed of execution of a specific piece of code?

    Is there a structure that can encapsulate the code to make the code have absolute priority when the code is executed?

    Thank you

    Set property "reporter Panel" updates on the front panel of the VI true before the beginning of your code, and set it to false afterwards. This should stop the table blinking when you disable and change the color and will considerably speed up updates.

    Here is an example:

  • How to increase the performance of xy-graph

    Hello

    I'm running a continuous collection of data with a NI PCI 6133 (4 x channel HAVE @ 2, 5MS/s each) on a WIN 7 PC (LabView FDS 2012). Inside a while loop I'm able to acquire 2000 samples per loop for each channel with a stable performance loop of about 1, 25 kHz. Out of these data, I'm 24 calculation values that will be shown on 6 xy-graphs (4 values on each chart). Data acquisition runs up to 2 minutes.

    Preparation of data and setting xy-graphs updated seems to be a big bottleneck. For this I wrote a simple point of interest, by comparing the xy-graph and table diagram performance clearify. For the same amount of data, the chart table is about 3 times faster, according to the ability to draw only the last value again. The xy-graph must update the whole plot of each iteration.

    If I also remove the preparation of complex data of the xy-chart, the chart diagram is up to 6 times faster.

    Landmark xy-graph

    Diagram graph of reference (including the preparation of data for chart xy)

    Benchmark graph diagram (without preparation of data for chart xy)

    Questions

    -Are there a way to optimize the data part of preparation of the xy-graph?

    -Is it possible to draw only the last value again in a xy chart as a graphic diagram?

    Why can I not use a graphic diagram?

    -Because the time base is not constant.

    My ideas:

    (1.) during measurement, I use a graphical diagram. I know that there will be some failure according to the variable time base. After the acquisition of the acquired data will be shown in xy-graphs (as an only necessary update) with the good time base.

    2.), I show all the data in a xy chart. Maybe just values the last 1000 would be sufficient.

    XY-graph with simply display the last 1000 values of reference

    Are there other ideas how to speed up xy-graphs?

    Thank you very much and best regards,

    Michael

    MichaGue_01 wrote:

    Why can I not use a graphic diagram?

    -Because the time base is not constant.

    This does not mean that you cannot use a chart.  You should read my injurywaveform charts nugget.  As long as you acquire your DAQmx device signals, you can wire all your signals directly in the table and it will load the time base.

  • How to improve the performance of your computer and free up space.

    Original title: the unwanted temporary files of windows is at the origin of the problems of proformanace

    According to a check of problem: the unwanted files temporary windows could take to improve the performance of your computer and free up space.

    Can anyone help with this simple problem.

    Angelo

    Hi Angelo,.

    1. which edition of Windows are you running?
    Example: Windows 7 Professional 32 bit.
    Please follow the below link to clean unwanted temporary files.
    Delete files using disk cleanup
     
    Microsoft at home.
    Slow PC? Optimize your computer for peak performance
    Make slate: how to remove the unwanted files and programs
     
    I hope this helps.
  • OfficeJet 6500 a, subject C2FE0122 error message. What is the meaning of this code?

    This printer a little over a year old demanded a replacement Printhead and printhead frequent cleaning. Is there a solution to this problem?

    Given that the error is not accompanied by the words 'Ink system failure' this alphanumeric code points to a problem overall impression material. Here a link to a document that deals with the alphanumeric codes for your printer model. It will show you how to reset the product. I hope this helps.  If you reach the end of this document and the issue is not fixed, sought to replace the product.

    If you are still in warranty, HP can replace the printer without cost to you. I'll link the information to get in touch with them below. The link takes you to a form to fill out. Once you fill it and she is treated, it will give you the printers warranty information, a file number and the phone number to call. Technical Support case HP formula call: https://h10025.www1.hp.com/ewfrf/wc/phoneInput?cc=us&dlc=en&lc=en&product=5061082

  • How to improve the performance of XControl?

    Hi all

    LabVIEW 2009 + DSC

    Following project example, there are 1 XControl and tester.vi. My goal was to display object flexible to build (1 XControl) because my user interface varies a lot depending on the current configuration of the client. The amount of these XControls are in general 100-200 pieces per display. The problem is that this structure of code generates much CPU load (even it's very simple). This can be seen easily when tester.vi is set to run. In general is it a way to improve the perfomance XControl?

    Some ways to improve performance:

    1. Never use a value property when you can use a local variable.  The difference in speed is two or three orders of magnitude.  You have several instances of this.
    2. Consider changing your data structure so that the number of the object and the position of the object are parallel arrays.  This allows to easily search item number using the primitive Research 1 table D , then check out the item appropriate to the position of the object by using the Table of Index.
    3. You should really not have anything in the XControl enabling to stop or delay the execution, because this will block your user interface thread.  Your VI popup for this.  If you need to pop up a dialog, run it with the method run a VI wait until is set to FALSE and Auto have Ref set to TRUE. To communicate the result to the XControl, drop a control hidden on the Panel before the XControl, pass a reference to this control in your dialog box, then use the value (signalling) method to contact the XControl to the dialog box.  Use a change in the value of the hidden control event to manage the receipt of data on the XControl.

Maybe you are looking for