Subscribe ( )

iPhone Programming Tutorials


 

Forum

You must be logged in to post Login Register

Search 

Beginner – How can I duplicate objects?

User Post

1:57 am
March 22, 2009


Cesar

Noob

posts 1

1

Hello everyone. Im a newbie here with a question.

I have gone through the game programming tutorials and managed to understand them and make my own pong version with several changes to the original code.

Now Im trying to experiment with a game of my own but theres one thing that I must know first: how can I duplicate an object maintaining its usability?

What I mean is, take the tutorial for example (the tennis – pong game). If I wanted to duplicate the paddles or the ball… how can I duplicate them without duplicating everything (the outlets, the actions and the code itself)?

The game PapiJump comes to mind. There are just two elements there, the smiley and the blocks on which the smiley can jump on. I suppose the programmer (sorry, I dont remember his name) coded just one block and then programmed the app so that this one block would procedurally duplicate itself retaining the collision properties.

So, thats pretty much it. And Im sorry if I was too repetitive LOL. Thanks in advance and a big CONGRATULATIONS to Brandon, this site rocks!

12:19 pm
March 27, 2009


maniacdev

Noob

posts 1

2

You've sort of answered your own question there Cesar. 

You would procedurally duplicate the collisions, probably the easiest way to do that would be to have an array containing the coordinates and type of terrain used on the playing area.

To duplicate a paddle in Object Oriented programyou would simply instantiate more than one paddle  eg.

Paddle paddle1 = [Paddle init];

Paddle paddle2 = [Paddle init];

and make the location variable of the paddle different for each paddle, along with the player types etc. ..

eg.

paddle1.location=whatever

paddle2.location=whatever


I hope this isn't too confusing, but essentially you just create 2 different paddles… a class is simply a blueprint, and many objects can be created from that blueprint with different properties.

Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

3 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 934 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.