(NO.00003) iOS games simple robot projection game forming notes (14th)

Source: Internet
Author: User

(NO.00003) iOS games simple robot projection game forming notes (14th)

First, we must store all the robots in the Level in an array, because the array will be accessed in different places. We put it in the LevelRestrict class, and we should put it in the GameState class in principle, here is a simple example.

Open LevelRestrict. h and add two new attributes to the interface:

@property (nonatomic,strong) Robot *selectedRobot;@property (nonatomic,strong) NSArray *robotsInLevel;

SelectedRobot indicates the selected robot. The robotsInLevel array is used to store all robot instances in the current Level.

Because you need to hold down the screen and move the arm, you need to respond to user interaction in MainScene. at the same time, because Arm is in the Level, two overlapping layers must respond to user interaction. In another separate blog, I detail how to handle touch in multiple overlapping layers, you can view it in the past. Here we will not go into details:

Priorities of overlapping touch layers in Cocos2D v3.x

Add the following code to its didLoadFromCCB method:

self.userInteractionEnabled = YES;

At the same time, modify the original code as follows:

    _restrict = [LevelRestrict sharedInstance];    _level = [CCBReader load:_restrict.levelName];    [self addChild:_level z:100];    _interface.zOrder = 200;

Currently, MainScene is in the order of 0, level is in the order of 100, and UI is in the highest order of 200. this error is ignored because the UI does not respond to user input. it has the highest Z order because the display information is not blocked by the subsequent content.

Now the arm in Level receives the touch event first. If it is processed, it will not be passed down; otherwise, it will be passed to the processing callback of MainScene.

MainScene does not send a mobile message directly to the arm, but sends the message to the Robot and the Robot moves the arm. Therefore, we need to modify the Robot interface method. For details, refer to the following section.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.