简体   繁体   English

如何制作看起来像此Cortex接口的接口? (圆圈,cocos2d,iphone)

[英]How make a interface that looks like this Cortex interface? (Circle,cocos2d,iphone)

How can I make such an interface with cocos2d for iphone? 如何使用cocos2d for iPhone建立这样的界面? Cortex interface 皮质接口

在此处输入图片说明

I already made a subclass of CCSprite and override the draw 我已经做了CCSprite的子类并覆盖了绘制

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? 另一个问题是触摸检测..可能只是cgrects? but what if i have more than 4 cells and one cell is "rotated"? 但是,如果我有4个以上的单元格并且一个单元格被“旋转”,该怎么办?

Any ideas? 有任何想法吗?

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. 我认为您在这里有两个选择,但是我不建议将CCSprite子类化,实际上很少会推荐这样做,几乎没有必要。

In my opinion, you could do either of these to get your image. 我认为,您可以选择其中任何一种来获得自己的形象。
1. Use OpenGL to draw your image. 1.使用OpenGL绘制图像。
2. Use CCSprite to draw your image. 2.使用CCSprite绘制图像。 (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 (sourcepos)并创建您的皮质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. 现在,使用简单的角度,我们可以使用if语句在CCSprite上安装不同的边界。 Its also a good idea to use #define kMinMagnitude X statement to ensure the user moves their finger adequately. 使用#define kMinMagnitude X语句以确保用户充分移动手指也是一个好主意。
  4. I suppose you can either execute the //Load Twitter or Load Facebook either on the movement or the cancelation of a touch. 我想您可以在移动或取消触摸时执行// Load Twitter或Load Facebook。 Thats entirely up to you. 完全由您决定。

(PSUDOCODE): (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

I don't think making a subclass of CCSprite is the right choice here. 我不认为在这里创建CCSprite的子类是正确的选择。 You will probably want a NSObject that creates the CCSprites for you. 您可能需要一个NSObject为您创建CCSprites。

Also CCSprite.position = CGPointMake( X, Y ) should allow you to set the position of the sprite. 同样, CCSprite.position = CGPointMake( X, Y )应该允许您设置子画面的位置。 Don't forget to add it to a layer just like any other CCNode object. 别忘了像其他CCNode对象一样将其添加到图层中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM