Subscribe ( )

iPhone Programming Tutorials

 

Forum

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

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.


About the iCodeBlog forum

Currently Online:

2 Guests

Maximum Online: 44

Forums:

Groups: 2

Forums: 6

Topics: 320

Posts: 760

Members:

There are 678 members

There are 1 guests


Brandon has made 87 posts

Top Posters:

bobcubsfan - 54

crazyiez - 30

VertigoSol - 26

Uhu - 17

AdeC - 17

Administrator: Brandon | Moderators: VertigoSol


© - Version 3.1.4 (Build 357)