-
Notifications
You must be signed in to change notification settings - Fork 74
Questions and Comments
Questions that I am asked about KnightFight I will post here, in case they may be of interest to people writing a similar game.
Q. My game is similar like the one you've posted, but is different in many places. I need your help if you can to make the map scrollable by the user finger.
A. I got a lot of help from the following page http://www.cocos2d-iphone.org/wiki/doku.php/resources:iphone_recommended_reading in particular the three "How to make a tile based game" tutorials. You may have already seen these, but I thought they were worth mentioning just in case.
To get the map to scroll with the users finger, there is some sample code here, in particular in the ccTouchesMoved method. http://www.cocos2d-iphone.org/forum/topic/19188 There are two sections depending on how many fingers are used, the first implements pinch & zoom functionality (which you may not want), and the second handles scrolling the map with the finger.
Q. I need more than one player on the screen, and they have to be selectable by tapping on them, and only on that selected are acts to the touch commands, so, if I've selected playerX, and I told him to go to somewhere in the map by tapping that position, only he will go there, right now, in the project you've posted, I can to scroll the map, and tell the player to go anywhere, and what we have to do is, making the player object to be like the attackers one, so if there is many player spawns on the map, they will get drawn and will acts only if they are selected.
A. I think the selecting of the players can be handled by using a ccTouchEnded method. You'll need to compare the coordinates of the touch with the current coordinates of all of the players, and if it's within a small distance of a player you can switch control to that player. You'll need to use a property to store the index of the player that is currently in use. If the touch is not near a player, you can count this as being an instruction for the currently selected player to move, and animate & move the currently selected player.
Q. I need the player to have path finding to arrive at the destination, I saw that you have a class for that, and currently I'm looking how to apply it to the player object.
A. You can use my pathfinding algorithm for the players. I assume you are going to have the non-selected player characters switching to AI (e.g. pathfinding) to continue moving around?
Pathfinding is quite intensive, and I had loads of trouble getting the game to run smoothly. If you have pathfinding running in the main game loop, you'll find the screen update will degrade quite badly. If memory serves me correctly, I think I set a thread for each attacker in the attacker class, and had the algorithm running within that. You can have a thread property in your player class, so each player has its own thread to run the algorithm. . Another tip is to use a timer to only recalculate the paths after a certain time interval, or when the end of the current path is reached.