Tap node in SpriteKit

So, I'm working on creating a tower defense game, and the tile works and is able to place towers ... to some extent.

When a player presses a button above the grid, he switches to placing the tower and allows the player to place towers on a cell in the grid. However, each tower also receives a ShapeNode circle around it to handle the detection of creep moving in firing range. This node shape only displays around the tower as soon as I have placed them.

The logic I used to place the tower is that it finds the node you are touching (called the cell) and replaces it with the node tower. But if the node tower has a node circle attached and covering the neighboring cell, I cannot select the node cell below the circle.

How would I touch “through” the circle or set its fill space to be nothing so that I can access the cells below it?

I am still studying a set of sprites, as if there might be a simpler approach, feel free to point me in the right direction.

+4
source share
3 answers

- , , , , node. , node , . , node. node .

+3

node , node, nodesAtPoint:, SKNode SKScene.

node, . , node, , , node node.

, enumerateBodiesAtPoint: usingBlock: SKPhysicsWorld

, AtPoint: , enumerateBodiesAtPoint: usingBlock: .

+4

TouchesBegan , .

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches)
    {
        CGPoint touchPoint = [touch locationInNode:self];
        NSArray *nodes = [self nodesAtPoint:touchPoint];

        if ([nodes count])
        {
            for (SKNode *node in nodes)
            {
                if ([node.name isEqualToString:@"cell"])
                {

                }
                else
                {

                }
            }
        }
    }
}

"self", which is the node that touches the start, is called (most likely your scene). You can also filter it with parent objects, for example; if you add all your nodes to the parent node named "background", you can only filter the children of the background node node, replacing "self" with your background node (although this will use the coordinates of the background nodes).

0
source

Source: https://habr.com/ru/post/1536184/


All Articles