2011-08-23 87 views
1

我已經無法找到這在文檔中。如何設置在層CC3Node的位置?

我有一個CC3Node(myNode),我的圖層有touchDown的回調& touchMoved事件到目前爲止,所有這些事件都起作用。我試圖在屏幕上拖動myNode,最好使用屏幕座標。

如何設置MYNODE的位置相對於屏幕(層)座標?

回答

1

好吧,我終於跟蹤下來,雖然件件有點多個職位散落。我最終的解決方案看起來是這樣的:

MyWorld.m:

// Error checking and misc removed 
- (void) addBackgroundForProjection 
{ 
    // background plane supports touch events 
    background = [CC3PlaneNode nodeWithName: BACKGROUND_PROJECTION_PLANE_NAME]; 
    [background populateAsCenteredRectangleWithSize: CGSizeMake(10.0, 10.0) 
             withTexture: [CC3Texture textureFromFile: @"transparent1x1.png"] 
             invertTexture: YES]; 
    [background setIsOpaque: NO]; 
    [background retainVertexLocations]; 
    [background setLocation: cc3v(0, 0, 0.001)]; 

    [self addChild: background]; 
} 

// ... 

- (void) moveNode: (CC3Node*) node toScreenLocation: (CGPoint) point 
{ 
    // update node on screen 
    CC3Plane groundPlane = self.background.plane; 
    CC3Vector4 touchLoc = [self.activeCamera unprojectPoint: point ontoPlane: groundPlane]; 
    CC3Vector newLoc = cc3v(touchLoc.x,touchLoc.y,touchLoc.z); 
    [node setLocation: newLoc]; 
} 
+0

請接受這個答案,如果它幫助你。這使用戶有相同的問題感興趣的答案,然後只有人可以標記這個問題的重複。 – rptwsthi