How To Make a Tower Defense Game

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

How To Make a Tower Defense Game

Postby rwenderlich » Fri Aug 17, 2012 11:00 am

This is the official thread to discuss the following blog post: How To Make a Tower Defense Game
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2215
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 359 times

Re: How To Make a Tower Defense Game

Postby rrdz473 » Fri Aug 17, 2012 4:26 pm

Great tutorial. Will certainly give it a try.
User avatar
rrdz473
Uber Haxx0r
 
Posts: 51
Joined: Wed Jun 01, 2011 12:45 am
Has thanked: 4 times
Been thanked: 1 time

Re: How To Make a Tower Defense Game

Postby Psevertson » Sat Aug 18, 2012 12:00 am

Great tutorial! I have been waiting for this one!
Another great tutorial for this topic is at: http://www.iphonegametutorials.com/2011 ... he-iphone/
You can combine ideas from both of them!
Psevertson
Baby Hacker
 
Posts: 9
Joined: Sat Mar 10, 2012 1:06 am
Has thanked: 1 time
Been thanked: 1 time

Re: How To Make a Tower Defense Game

Postby mountainmarc1972 » Sat Aug 18, 2012 10:59 am

In the starter projects Appdelegate you forgot to enable retina display by removing the // at line 73
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");

Thanks for the great tutorial !
mountainmarc1972
n00b
 
Posts: 3
Joined: Fri Jun 01, 2012 5:55 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Tower Defense Game

Postby JohnL » Sat Aug 18, 2012 4:57 pm

Superb tutorial as always!!

One minor thing, at the end of the tutorial where it says open Enemy.M and add the lines #import "SimpleAudioEngine.h"
This is not needed as the line is already in there from earlier when you created the Enemy class.

@mountainmarc1972
For me, removing the // at line 73, then running it on an iphone 4 makes things go funny. The waypoints and tower placements are ok, but the background picture is smaller than the screen (due to retina) and the enemy heath bars are out of place...
It looks ok on the Simulator though.


Keep up the good work!
JohnL
Hacker
 
Posts: 10
Joined: Sat Aug 18, 2012 4:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Tower Defense Game

Postby Rabbitpuncher » Sun Aug 19, 2012 10:49 pm

I keep getting the following error which seems to point to glColor4f in the draw method.

Implicit declaration of function 'glColor4f' is invalid in C99


I also get
OpenGL error 0x0502 in -[CCSprite draw] 532
in the console when I run it.

I'm running Cocos2d 2.0. Any ideas why I get this?
Rabbitpuncher
Subscriber since Sep 24, 2014
Baby Hacker
 
Posts: 9
Joined: Tue May 01, 2012 1:06 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Tower Defense Game

Postby Pabloruiz55 » Mon Aug 20, 2012 6:49 pm

@Rabbitpuncher: Oh, this is because that funcion to draw the life bars deal with Opengl 1.x calls, that is why it doesn;t work with Cocos2d 2.x (Which uses OpenglES 2.0). I am no OpenGl expert so I wouldn't know how to translate them to 2.0, can anyone help?
User avatar
Pabloruiz55
Hacker
 
Posts: 10
Joined: Thu Jan 26, 2012 9:19 am
Location: Buenos Aires, Argentina
Has thanked: 0 time
Been thanked: 1 time

Re: How To Make a Tower Defense Game

Postby Rabbitpuncher » Mon Aug 20, 2012 9:04 pm

Pablo...I'll research that a bit and see. Thanks...I love the tutorial!
Rabbitpuncher
Subscriber since Sep 24, 2014
Baby Hacker
 
Posts: 9
Joined: Tue May 01, 2012 1:06 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Tower Defense Game

Postby doninox » Wed Aug 22, 2012 2:10 am

TowerPosition.plist have 12 Items but in loadTowerPositions method
towersBases = [[NSMutaleArray alloc] initWithCapacity:10];
why is 10 than 11 ?
doninox
n00b
 
Posts: 1
Joined: Wed Aug 22, 2012 2:00 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Tower Defense Game

Postby tomneo2004 » Wed Aug 22, 2012 10:23 am

If you are using Cocos2d 2.x use "ccDrawSolidPoly" method to draw health bar.
In Enemy.m "draw" method replace code to
Code: Select all
 
    CGPoint healthBarBack[] = {ccp(mySprite.position.x -10,mySprite.position.y+16),ccp(mySprite.position.x+10,mySprite.position.y+16),ccp(mySprite.position.x+10,mySprite.position.y+14),ccp(mySprite.position.x-10,mySprite.position.y+14)};
 
    ccDrawSolidPoly(healthBarBack, 4, ccc4f(255, 0, 0, 255));
   
 
    CGPoint healthBar[] = {ccp(mySprite.position.x + HEALTH_BAR_ORIGIN,mySprite.position.y+16),ccp(mySprite.position.x+HEALTH_BAR_ORIGIN+(float)(currentHp * HEALTH_BAR_WIDTH) / maxHp,mySprite.position.y+16),ccp(mySprite.position.x+HEALTH_BAR_ORIGIN+(float)(currentHp * HEALTH_BAR_WIDTH) / maxHp,mySprite.position.y+14),ccp(mySprite.position.x+HEALTH_BAR_ORIGIN,mySprite.position.y+14)};

    ccDrawSolidPoly(healthBar, 4, ccc4f(0, 255, 0, 255));


Use ccDrawSolidPoly instead of ccFillPoly.
ccFillPoly will cause problem in coco2d 2.x.
tomneo2004
Hacker
 
Posts: 29
Joined: Wed Jun 13, 2012 6:43 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: Bing [Bot] and 5 guests