Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit class #8

Open
Isaac-W opened this issue Nov 20, 2014 · 2 comments
Open

Add unit class #8

Isaac-W opened this issue Nov 20, 2014 · 2 comments
Assignees
Labels
Milestone

Comments

@Isaac-W
Copy link
Contributor

Isaac-W commented Nov 20, 2014

Unit class should hold all attributes pertaining to a single unit in play, according to Naturalize documentation. For the most part, I think that at least getting the attributes put in place is a start. Looking at the documentation, the methods can mostly all be implemented, with exception of a move() method, which we will look into splitting up once more of the engine comes along in the next week or so.

@Isaac-W Isaac-W added this to the Alpha 1 milestone Nov 20, 2014
@Isaac-W
Copy link
Contributor Author

Isaac-W commented Nov 21, 2014

Assigned to @sanderzinc to cooperate with @adamcarlson in implementing this.

@Isaac-W
Copy link
Contributor Author

Isaac-W commented Nov 25, 2014

Okay, so I've determined that all objects visible on the screen should subclass Node. So, the Unit class should inherit from public cocos2d::Node. Then, inside the Unit class, you can have all sorts of Sprites that are members of that class. All you need to do is, inside the init() method (which is called when you create the object), add those Sprites as children of the Unit instance. This will associate those Sprites with the Unit instance (the instance itself is technically invisible because we don't specify any custom drawing code, but its children Sprites will be drawn instead).

Any children of a Node will automatically move and scale along with the parent Node, which means that we can directly operate on the Unit class itself without any knowledge of its children Sprites. For example, I have written some sample code that creates a test lumberjack unit and moves him relative to the map. The TestUnit class inherits from Node, and has a Sprite member variable. This Sprite is what holds and draws the lumberjack image. In the init() code for TestUnit, the lumberjack Sprite is added to TestUnit as a child, meaning that the two form a forever inseparable bond of parent and child. Furthermore, in the main GameScene, I create a TestUnit instance and attach that to the map as another child, meaning that, when the map moves, the TestUnit and by extension the lumberjack Sprite move with it. You can run the test and move the map around to see this in action.

tl;dr Look at commit b4850fa for the TestUnit, and make sure that the Unit class you're designing also inherits from cocos2d::Node in the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants