cocos2dx画连接任意两点的绳子【始终连接触摸点与屏幕中心】
最近在搞连线的游戏,之前的博客里也提到了用DrawNode画粗线的方法。(http://blog.csdn.net/no99es/article/details/38823673) 线画出来之后,就想用绳子代替它,由于三角函数忘光了,耽误了时间,今天终于搞完了,记录下来。 使用的绳子图片: 网上找的,
最近在搞连线的游戏,之前的博客里也提到了用DrawNode画粗线的方法。(http://blog.csdn.net/no99es/article/details/38823673)
线画出来之后,就想用绳子代替它,由于三角函数忘光了,耽误了时间,今天终于搞完了,记录下来。
使用的绳子图片:
网上找的,横向的绳子。
原理:
用setTextureRect方法,显示指定长度的绳子,然后根据触摸点坐标,进行旋转。
下面贴出两段关键代码:
/*
*添加触摸监听
*/
auto myListener = EventListenerTouchOneByOne::create();
//myListener->setSwallowTouches(true);
myListener->onTouchBegan = CC_CALLBACK_2(LineTest::TouchBegan, this);
myListener->onTouchMoved = CC_CALLBACK_2(LineTest::TouchMoved, this);
myListener->onTouchEnded = CC_CALLBACK_2(LineTest::TouchEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(myListener, this);
触摸方法里,Began跟Moved代码差不多,大家自由发挥~~
bool LineTest::TouchBegan(Touch* touch, Event* event)
{
spline->setVisible(true);
//长度,触摸点到屏幕中心的距离
int texturehight = sqrt(pow((touch->getLocation().x - visibleSize.width / 2 + origin.x), 2) + pow((touch->getLocation().y - visibleSize.height / 2 + origin.y), 2));
spline->setTextureRect(Rect(0, 0, texturehight, 40));
//旋转
float x = touch->getLocation().x - visibleSize.width / 2.0f + origin.x;
float y = touch->getLocation().y - visibleSize.height / 2.0f + origin.y;
float f = GetRotationDegree(x, y);
spline->setRotation(f);
return true;
}
///////////////////获取旋转角度//////////////
float LineTest::GetRotationDegree(float x, float y)
{
if (x == 0 && y == 0)
{
return 0;
}
float result;
if (x == 0&&y>0)
{
return 90;
}
else if (x == 0 && y
{
return 180;
}
else
{
float temp = y / x;
result = - atan(temp) * 180.0 / M_PI;
if (x>0)
{
return result;
}
else
{
return result+180;
}
}
}
效果:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to connect the keep body fat scale? Keep has a specially designed body fat scale, but most users do not know how to connect the keep body fat scale. Next is the graphic tutorial on the connection method of the keep body fat scale that the editor brings to users. , interested users come and take a look! How to connect the keep body fat scale 1. First open the keep software, go to the main page, click [My] in the lower right corner, and select [Smart Hardware]; 2. Then on the My Smart Devices page, click the [Add Device] button in the middle; 3 , then select the device you want to add interface, select [Smart Body Fat/Weight Scale]; 4. Then on the device model selection page, click the [keep body fat scale] option; 5. Finally, in the interface shown below, finally [Add Now] at the bottom

Screenshot feature not working on your iPhone? Taking a screenshot is very easy as you just need to hold down the Volume Up button and the Power button at the same time to grab your phone screen. However, there are other ways to capture frames on the device. Fix 1 – Using Assistive Touch Take a screenshot using the Assistive Touch feature. Step 1 – Go to your phone settings. Step 2 – Next, tap to open Accessibility settings. Step 3 – Open Touch settings. Step 4 – Next, open the Assistive Touch settings. Step 5 – Turn on Assistive Touch on your phone. Step 6 – Open “Customize Top Menu” to access it. Step 7 – Now you just need to link any of these functions to your screen capture. So click on the first

When many friends are using their mobile phones, they suddenly find that the operation interface of the mobile phone has turned into "black and white" color. They don't know what causes it or how to solve it. This article uses Android mobile phones as an example to teach you how to make it work. The color of the mobile phone's operating interface returns to normal. 1. Set up the interface of the mobile phone and find the "gear-shaped" icon in the operation interface. As shown below: Click this icon to enter the phone’s settings interface. 2. Options The operating interface of the mobile phone has changed to black and white, which is related to the "Display" setting of the mobile phone. After entering the settings interface of the mobile phone, find the "Display and Theme" option in the drop-down menu, as shown below: Then click "Display and Theme" option to enter the details page. 3. After changing the screen color and entering the "Display and Theme" option, find the "

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

I believe many friends have encountered the problem that their mobile phones suddenly prompt: Do not cover the top of the screen. So why does the mobile phone suddenly appear like this? Let’s take a look together below. In fact, when this happens, something is blocking the distance sensor of the phone, so this prompt is received on the screen of the phone. So why did I suddenly receive such a prompt? In fact, it may be that you have accidentally turned on the [anti-accidental touch mode] on your phone, so this problem occurs. So how do we close it? In fact, the method is very simple. Let’s take a look at it together. Method 1: Directly follow the on-screen prompts to close using the shortcut key combination. Method 2: If the above method does not work, you can also open the phone’s [Settings]

Although it will be a long time before the release of the iPhone 16 series, there have been constant revelations about the appearance and configuration. According to Korean media SisaJournal, Apple plans to introduce new ultra-narrow bezel technology in the upcoming iPhone 16 series of mobile phones. The technology involves rolling internal copper wires into a more compact structure to reduce the bezel width of the phone's bottom display, allowing for a larger display. This innovative move aims to enhance the user experience, allowing users to enjoy a wider field of view and a more immersive entertainment experience. Apple has always been committed to continuously improving its product design and technology to bring more advanced functions and performance to users. The launch of the iPhone 16 series of mobile phones will further consolidate Apple’s leadership in smart phones. According to @SnapaDigital, Apple’s new

According to news on July 23, blogger Digital Chat Station broke the news that the battery capacity of Xiaomi 15 Pro has been increased to 6000mAh and supports 90W wired flash charging. This will be the Pro model with the largest battery in Xiaomi’s digital series. Digital Chat Station previously revealed that the battery of Xiaomi 15Pro has ultra-high energy density and the silicon content is much higher than that of competing products. After silicon-based batteries are tested on a large scale in 2023, second-generation silicon anode batteries have been identified as the future development direction of the industry. This year will usher in the peak of direct competition. 1. The theoretical gram capacity of silicon can reach 4200mAh/g, which is more than 10 times the gram capacity of graphite (the theoretical gram capacity of graphite is 372mAh/g). For the negative electrode, the capacity when the lithium ion insertion amount reaches the maximum is the theoretical gram capacity, which means that under the same weight

Are you trying to record something on your phone screen and it's going black? Typically, you can initiate screen recording from Control Center. In some cases, you cannot record items on the screen. We have mentioned all the scenarios along with the list of possible solutions that can help you record your screen properly. Reasons why screen recording goes black – If you try to record any DRM (Digital Rights Management) protected content while it’s playing on your iPhone screen, you won’t get anything. The output will be a pitch black screen. All leading OTT platforms like Netflix, Disney+, Hulu, and Peacock have this DRM that blocks any screen recording functionality. 2. Several websites prohibit the use of screen capture
