0

I create multiplayer game. I used this tutorial for create my game:

Game Center part 1

Game Center part 2

My issues now is: - how to shared data for all players.

In tutorial Ray Wenderlich we can send data with struct. We send struct and we have ability get the simple data (for example int value or other). How to send data without struct?

Thanks for response!

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277

1 Answers1

1

NSObjects are pointers, so if you try and send it you will just send the pointer rather than the object. My suggestion is that you implement a -serialize method for your subclass, which converts your object to either a string or to numbers. Then implement a -deserialize method to do the reverse. I can't help you with the nature of these methods, as I do not know what your NSObject contains, but only send the bare minimum of data.

Sidenote: Why can't you use structs?

jrtc27
  • 8,496
  • 3
  • 36
  • 68
  • Thank you for your reply. I also tried to use NSCoder or other method for this, but I do not know very well how to handle it. So, (Why can't you use structs?) When I tap on the screen, I need to define my touch location. I tried to send NSSet object. – Matrosov Oleksandr Jan 12 '12 at 15:37
  • For example: typedef{ MessageType type, __unsafe_unretained NSSet*touches }somestruct; – Matrosov Oleksandr Jan 12 '12 at 15:43
  • Don't use pointers in your struct. Instead get the coordinates of the touch as floats and store those in your struct. – jrtc27 Jan 12 '12 at 18:28
  • And if you have multiple touches, either send a C-array of touches in the struct (make sure to include the number of touches in the packet) or send multiple packets. – jrtc27 Jan 12 '12 at 18:29
  • thanks! yes I agree it's one of the solutions. can you explain me - how to serialize/deserialize my object? – Matrosov Oleksandr Jan 13 '12 at 10:15