Many mobile apps now have the function of simulating the joystick. Today, the project has encountered a delegate event. I will try to implement this joystick function by the way.
The Code is as follows:
/** Joystick. H * yaogan ** created by Liu Yanghui on 11-10-27. * copyright 2011 ard8. All Rights Reserved. **/# ifndef joystick_h # define joystick_h # include "cocos2d. H "using namespace cocos2d; Class joystick: Public cclayer {public: ccpoint centerpoint
There are a lot of such methods. I have found one for you on the internet, but this is not complete yet. How can I determine whether the buttons are left or right. So I added some stupid methods. If you have any good methods, I 'd like to comment out. Thank you.
[Cpp]# Include "cocos2d. h"Using namespace cocos2d;Class Joystick:Public CCLayer[Cpp]Public:Joystick (void );~ Joystick (void );Public:CCPoint centerPoint; // joystick CenterCCPoint currentPo
In fact, it is not difficult to implement this function. simply copy the logic previously implemented in Java... Let's take a look at the following:
First, the joystick is regarded as an independent class and has its own series of functions. The Code only lists some of the most commonly used functions:
Joystick. h:
# Include "cocos2d. H" using namespace cocos2d; Class joystick: Public cclayer {public: joystick (void );~ Joystick (void); Public: ccpoint cente
Motivation : Capture the internal state of an object without compromising encapsulation, and save the state outside the object. In this way, the object can be restored to the previously saved state.
Scenario: The Graphic System is used as an example. The circle is the primary machine. The system processes the circle and stores the recoverable sequence.
Structure chart
Code
Namespace
Designpattern. Memento
{ /**/ //////Primary machine/// Public Class Round { Private
, this );Postmessage (wm_null, 0, 0 );3. animation effects displayed in the dialog box from small to large:Add:Showwindow (sw_hide );Crect dlgrect;Getclientrect ( dlgrect );Cpoint centerpoint;Centerpoint. x = dlgrect. Width ()/2;Centerpoint. Y = dlgrect. Height ()/2; // obtain the midpoint coordinate of the dialog box.Crgn testrgn;This-> showwindow (sw_hide );Int
method is still applicable to the blunt angle. Considering that the current mouse is in the second quadrant, the red dotted line vector and the blue solid line vector are used as reference vectors)
The algorithm is implemented as follows. The idea is basically the same as above, and only some optimizations are made:
Evaluate the dimensionline endpoint Algorithm
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
1
Private
Void
= fgetc (FP );If (feof (FP ))Break;If (CH = '/N' flag = 1)Continue;Else if (CH = '/N' flag = 0)Flag = 1;ElseFlag = 0;Fputc (CH, FP1 );}Fclose (FP1 );Fclose (FP );3. solution: Use the following code after the menu:Cpoint pt;Getcursorpos ( pt );Setforegroundwindow ();Policymenu. trackpopupmenu (tpm_rightbutton, Pt. X, Pt. Y, this );Postmessage (wm_null, 0, 0 );3. animation effects displayed in the dialog box from small to large: Add:Showwindow (sw_hide );Crect dlgrect;Getclientrect ( dlgrect );
(TPM_RIGHTBUTTON, pt. x, pt. y, this );PostMessage (WM_NULL, 0, 0 );3. animation effects displayed in the dialog box from small to large:Add:ShowWindow (SW_HIDE );CRect dlgRect;GetClientRect ( dlgRect );CPoint centerPoint;CenterPoint. x = dlgRect. Width ()/2;CenterPoint. y = dlgRect. Height ()/2; // obtain the midpoint coordinate of the dialog box.CRgn testrgn;T
1. Description: In WPF, File download needs to display the download progress, because the system comes with a bar-type progress bar compared to occupy space, instead of using a circular progress bar, need to be presented on drawingvisual.Effect of runningPrivatePoint Getpointoncir (Point CenterPoint,DoubleRDoubleAngel) {Point P =NewPoint (); p.x = Math.sin (Angel * Math.PI/ the) * r + centerpoint.x; P.Y = Centerpoint.y-math.cos (Angel * Math.PI/ the)
know that the Tag of the protagonist is 1, the Tag of the gold coin is 2, and the rock is 3;
Then add the code in the initBody so that it can be detected by collision:
Void Runner: initBody () {// set bodySize for different rigid bodies according to different States; if (m_state = crouch) {bodySize = crouchSize;} else {bodySize = run_jumpSize ;} // create the runner's rigid body auto runerBody = PhysicsBody: createBox (bodySize, PHYSICSBODY_MATERIAL_DEFAULT); // set the runerBody for Collision
,initWithCoderAdd the custom Initialization Method to the parent class constructor.initData.Override Plotting Method
As in AndroidonDraw(), In iOSdrawRectCan be rewritten and then called[view setNeedsDisplay].
- (void)drawRect:(CGRect)rect { _path = [[UIBezierPath alloc] init]; [self drawCenterCircle]; [self drawTouchCircle:_touchPoint]; [self drawBezierCurveWithCircle1:_centerCircle Circle2:_touchCircle];}
As mentioned in algorithm analysis, we only need to draw two circles (drawCen
the closest distance, and obtain the least recent point.
Calculate the closest distance from a point to a circle and the coordinates of the intersection.:
If the point is in the center of the center, undefined is returned because the distance from the center to any point in the circle is equal.
The connection point P and the center O. If the Po is parallel to the X axis, the abscissa of the nearest point is calculated based on P on the left or right of O as
vertical foot, and select the endpoint closer to the vertical foot to return.
Calculate the closest point of a point to a line, rectangle, or polygon:
You only need to calculate the closest point to each line segment, record the closest distance, and obtain the least recent point.
Calculate the closest distance from a point to a circle and the coordinates of the intersection point:
If the point is in the center of the center, undefined is returned because the distance from the center
:
The button outlines.
Step 2: Draw the background color of the button.
// Specifies the base color of the draw button.
Rect. DeflateRect (3, 3, 3, 3 );
CBrush * pOldBrush = pDC-> SelectObject ( m_BackgroundBrush );
PDC-> Rectangle (rect );
PDC-> SelectObject (pOldBrush );
Here is just a simple demonstration. The buttons are not necessarily nice. Set the base color of the button to pure white. The program execution result is as follows:
Step 3: Draw the text of the button.
// Draw button text
closest point of a point to a line, rectangle, or polygon:
You only need to calculate the closest point to each line segment, record the closest distance, and obtain the least recent point.
Calculate the closest distance from a point to a circle and the coordinates of the intersection point:
If the point is in the center of the center, undefined is returned because the distance from the center to any point in the circle is equal.
The connection point P and the center O. If the Po is para
The most basic animation effect is transform, which can be divided into translate, rotate, scale, skew, and flip. Below is a brief summary.
Translate: as long as it is a change in position (based on the change in the position of the animation object X, Y axis)
Rotate: Self-rotation. In blend, the rotate under the transform label is set to angle, angle> 0, clockwise rotation; angle
Scale: scale itself. For example: Scale x = 2, the X axis direction of the animation object is doubled,
Ske
, the DRDs row is returned; if not, calculate the distance between the two ends and the vertical foot, and select the endpoint closer to the vertical foot to return.
Calculate the closest point of a point to a line, rectangle, or polygon:
You only need to calculate the closest point to each line segment, record the closest distance, and obtain the least recent point.
Calculate the closest distance from a point to a circle and the coordinates of the intersection point:
If the point is i
;script>
script type="Text/javascript">
Get the coordinates of all points
var points = [
New Bmap.point (114.00100, 22.550000), New Bmap.point (114.00130, 22.550000),
New Bmap.point (114.00160, 22.550000), New Bmap.point (114.00200, 22.550000),
New Bmap.point (114.00300, 22.550500), New Bmap.point (114.00400, 22.550000),
New Bmap.point (114.00500, 22.550000), New Bmap.point (114.00505, 22.549800),
New Bmap.point (114.00510, 22.550000), New Bmap.point (114.00515, 22.550
Draw a CircleSolve the problem of drag and drop, and then you can implement drag-and-drop drawing circle. We pass in the center point to draw the initialization circle, the default radius is 500 meters,Startdrawcircle:function (centerpoint) { this._unregistmapevents (); This.centerpoint = CenterPoint; This.circle = This._createcircle (
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.