如何制作一个类似于 Cortex 接口的接口? (圆,cocos2d,iphone)

发布于 2024-10-31 07:51:32 字数 912 浏览 2 评论 0原文

如何用 cocos2d for iphone 制作这样的界面? 皮质接口

在此处输入图像描述

我已经创建了 CCSprite 的子类并重写 draw

方法,如下所示:

-(void)draw {
    ccDrawCircle(CGPointMake(480/2, 320/2), 70, 0, 50000, NO);
    ccDrawCircle(CGPointMake(480/2, 320/2), 25, 0, 50000, NO);

    ccDrawLine(CGPointMake(480/2, 320/2+25), CGPointMake(480/2, 320/2+70));
    ccDrawLine(CGPointMake(480/2+25, 320/2), CGPointMake(480/2+70, 320/2));
    ccDrawLine(CGPointMake(480/2, 320/2-25), CGPointMake(480/2, 320/2-70));
    ccDrawLine(CGPointMake(480/2-25, 320/2), CGPointMake(480/2-70, 320/2));

}

问题是我没有对圆圈的任何控制(无法设置它的位置)......而且我不知道如何将文本/图像放入这些“单元格”中。另一个问题是触摸检测..也许只是 cgrects?但是如果我有超过 4 个单元格并且其中一个单元格“旋转”怎么办?

有什么想法吗?

How can I make such an interface with cocos2d for iphone? Cortex interface

enter image description here

I already made a subclass of CCSprite and override the draw

method like this:

-(void)draw {
    ccDrawCircle(CGPointMake(480/2, 320/2), 70, 0, 50000, NO);
    ccDrawCircle(CGPointMake(480/2, 320/2), 25, 0, 50000, NO);

    ccDrawLine(CGPointMake(480/2, 320/2+25), CGPointMake(480/2, 320/2+70));
    ccDrawLine(CGPointMake(480/2+25, 320/2), CGPointMake(480/2+70, 320/2));
    ccDrawLine(CGPointMake(480/2, 320/2-25), CGPointMake(480/2, 320/2-70));
    ccDrawLine(CGPointMake(480/2-25, 320/2), CGPointMake(480/2-70, 320/2));

}

The problem is that I don't have any control over the circle (can't set the position of it)...and i don't know how to place text/images into these "cells". Another problem is the touch detection..mayby just cgrects? but what if i have more than 4 cells and one cell is "rotated"?

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉月流沐 2024-11-07 07:51:32

我认为你在这里有两个选择,但我不建议子类化 CCSprite,事实上很少会建议这样做,几乎没有必要。

在我看来,您可以执行以下任一操作来获得您的图像。
1. 使用OpenGL绘制图像。
2. 使用CCSprite 绘制图像。 (更清洁)

一旦你绘制了它,只需按下屏幕即可创建它。
一旦您按下屏幕(或任何规定的物体),我就会采用一个简单的三角函数解决方案。
这是我将使用的算法:

  1. 按下屏幕,获取触摸位置。 (sourcepos) 并创建你的皮层 img
  2. 在屏幕上移动手指时,获取位置 (currentpos) 相对于原始 (sourcepos) 触摸的角度和大小。
  3. 现在,使用简单的角度,我们可以使用 if 语句在 CCSprite 上安装不同的边界。使用 #define kMinMagnitude X 语句来确保用户充分移动手指也是一个好主意。
  4. 我想您可以在移动或取消触摸时执行 //Load Twitter 或 Load Facebook。这完全取决于你。

(伪代码):

dx = currentpos.x - sourcepos.x
dy = currentpos.y - sourcepos.y
mag = sqrt(dx*dx + dy*dy);
ang = CC_RADIANS_TO_DEGREES(atan2f(dy/dx));

if (ang > 0 && ang < 80 && mag > kMinMagnitude) //Load Twitter 
if (ang > 80 && ang < 120 && mag > kMinMagnitude) //Load facebook

I think you have two options here, but I don't recommend subclassing CCSprite, infact very rarely would recommend doing so, theres almost no need to.

In my opinion, you could do either of these to get your image.
1. Use OpenGL to draw your image.
2. Use CCSprite to draw your image. (Cleaner)

Once you have drawn it, its simply a matter of creating it when you press down on the screen.
Once you press down on the screen (or any prescribed object) I would then employ a simple trigonometric solution.
This is the algorithm I would use:

  1. Press down on screen, Get the position of touch. (sourcepos) and create your cortex img
  2. On Movement of finger on screen, get the position (currentpos) the angle and magnitude in relation to the original (sourcepos) touch.
  3. Now, using simple angles we can install different bounds on your CCSprite using if statements. Its also a good idea to use #define kMinMagnitude X statement to ensure the user moves their finger adequately.
  4. I suppose you can either execute the //Load Twitter or Load Facebook either on the movement or the cancelation of a touch. Thats entirely up to you.

(PSUDOCODE):

dx = currentpos.x - sourcepos.x
dy = currentpos.y - sourcepos.y
mag = sqrt(dx*dx + dy*dy);
ang = CC_RADIANS_TO_DEGREES(atan2f(dy/dx));

if (ang > 0 && ang < 80 && mag > kMinMagnitude) //Load Twitter 
if (ang > 80 && ang < 120 && mag > kMinMagnitude) //Load facebook
北方的巷 2024-11-07 07:51:32

我认为创建 CCSprite 的子类在这里不是正确的选择。您可能需要一个 NSObject 来为您创建 CCSprites。

另外,CCSprite.position = CGPointMake( X, Y ) 应该允许您设置精灵的位置。不要忘记将其添加到图层中,就像任何其他 CCNode 对象一样。

I don't think making a subclass of CCSprite is the right choice here. You will probably want a NSObject that creates the CCSprites for you.

Also CCSprite.position = CGPointMake( X, Y ) should allow you to set the position of the sprite. Don't forget to add it to a layer just like any other CCNode object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文