Summary of Program Development

Source: Internet
Author: User

A little Summary of program development, to help friends who want to learn a new language,: P

1. Processing under multiple conditions

Method 1: write one side of the function call for every condition that requires the execution of function A. This method is also the most common method, and the code is relatively bloated. If a has any changes, multiple modifications are required. This type of code block is too much to be written, which is easy to be missed.

if(b==1)a()else if(b==2)else if(b==3)a()elsea()

Method 2: Before filtering Condition B, create a temporary variable Boolean C to monitor the conditions required by function a. It must be true, if this parameter is not required, the system does not write (the default value is false). After the condition ends, the system judges C and processes function a at a time.

<span style="font-size:14px;">c=falseif(b==1)c=trueelse if(b==2)else if(b==3)c=trueelsec=trueif(c) a()</span>

Method 3: Filter Condition B to process the required filtering, and then filter Condition A again without any variable.

<span style="font-size:14px;">swich(b)case 1:xxxxxcase 2:yyyyycase 3:ddddddefault:ffffffswich(b)case 1:case 3:default:a()</span><span style="font-size: 18px;"></span>


(The efficiency of IF and switch is not discussed above. Any solution can be as good as you can)


2. latency Functions

First, let's look at the conditions. The same condition is triggered multiple times, generally from multiple objects to the response of this object. At this time, the response times may be known or unknown.

For the known Count, count under the Condition B, and then activate function.

<span style="font-size:14px;">int c=0;......if(b==1){ c++ if(c>=3) a()}</span>

However, in general, the best solution is to delay the execution of A, because this method neither calls a frequently nor causes a slow response, and a series of other problems, you only need to know the maximum interval between the activation conditions of a continuous sequence. Generally, this type of response requires a step difference, or dozens of milliseconds. A step difference is very simple and the delay is set to 0, because the latency function is created and executed in the next step, you can set the latency to 0 in a continuous for loop for example. Of course, in a controllable function such as, try not to write latency: P

<span style="font-size:14px;">if(b==1)delayDealFunc(A,delayTime)</span>

Of course, if function a is delayed, it will involve many problems, such:

A. debugging is completely traceable. If a large number of delayed calls are involved and a problem occurs, debugging may be difficult, it is reflected that resumable tracing only traces back to the delay method. It is difficult to determine what the delay function is called, which is also a weak language, you can only search for all the places where the delay a function is called and set breakpoints for tracking in advance.

B. delayed functions do not cause thread-level problems. After all, they are still in the same thread, but you should be careful that there may be thousands of possibilities after delay, and even functions do not exist, there is a lot of uncertainty in it. If you need to process some parameters, it is best to work with the delay function to enable the customer to travel around.


The delay function is quite practical. Here I will not talk about how to implement the delay function, how the code works, and every language has its own latency function. Let's figure it out.


3. Periodical execution functions

I think that when I come into contact with a language, I should first be familiar with the way it is written to log, and second I should be familiar with the interesting settings of periodic execution functions, which can implement many interesting things, this allows parameters to be moved, graphics to be moved, and programs to be moved. In short, it is just like the engine of the program.

Cyclic execution functions have fixed and adjustable cycles. The only difference is that if you use heavy processing with too many cycles, the engine may be exhausted, and the overall effect will become incomparable, terrible.


4. Notifications and events

Each language also has its own notification processing method, but I like to use the icationicationcenter execution method in obj-C. Although the efficiency is not high, the management is centralized, in addition, the coupling lines between notifications are the lowest, which is most convenient during multi-module development.

In game development, there will be a bubble notification method, which is relatively limited, but it is more efficient than NC

The most efficient is the direct control of objects and pointers with the highest coupling. If you have not felt any pressure for such a small project, you can continue to use it (SWEAT ), it is recommended that this method be used between objects with relatively high coupling between internal, local, and itself, with high efficiency.


5. Exercise Mode

Many times, we can use periodic functions to process motion, such as simple constant motion. however, most of the results are still presented to professional tween sports. in fact, this type of function is also very simple, that is, the formula we learned

In and out, the numeric value shows that the speed is getting slower and the acceleration is negative. Some tween also supports the inout smoothing curve, that is, the start is slow, the end is slow, and the center is slightly faster, relatively smooth motion Solution

Linear: constant speed, the simplest way of motion

Sin: sine motion. You can select different curves to produce out and in effects.

Square: square root, which is actually the Y = x square curve. Three root and four root Root are derived, which means the curve changes more quickly.

Elastic: elastic. It will swing left and right at the end and finally stop at the end.

Back: maneuver, first moving in the opposite direction before going to the end, or then approaching the end

Bounce: a bounce ball, similar to elastic, but does not reach the other end.

Exponential: exponential, moving according to the exponential curve

Generally, sineout, backout, and backin are commonly used.


6. Physical Engine

Although tween can help you a lot, if you need real object motion curves and collisions, tween will not be able to help you at all. You need a physical engine like God.


Write so much.: P





Summary of Program Development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.