开发者

Game Design - Reusing an objects properties?

I am new to Obj C, but have developed many types of games in Flash. I have multiple squares (UIImageViews) that have the exact same properties;

  • can be collision detected (converted to CGRect)
  • can have a background image (image.png)
  • 开发者_StackOverflow中文版
  • can set an int variable on itself to set state (0-3)
  • can be a type of square represented by another int variable (0-3)

In Flash I could create a movieClip instance and define it's properties on that instance. Then I can duplicate the instance and give it different names. Now all the instances can have their own properties set depending on their own state in the game.

How can I do this in OBJ C. Is there a way to define an object, like a UIImageView *square that also has a CGRect.frame, a .background property, an int state variable, and an int type variable? Then if I create an instance and name it square_01, square_02, etc... Is this possible?

The way I have it setup now looks like a giant list of properties as I am having to create a UIImageView, a CGRect, and 2 int vars, for each square that I know I am going to be creating. I want to refactor and simplify so that my code doesn't get out of hand as I feel is starting to be the case.

Thanks in advance,


In Flash, instances of MovieClip (or a subclass) act a bit differently than standard objects. They are basically designed to act as elements of a "world", so to speak, in the way that you want, with the ability to contain a lot of additional information beyond just their image representation and placement.

A UIImageView does no such thing. It is meant to display an image at a location on the screen, and that is all. Rather than try to treat it like a Flash MovieClip, try creating a separate class (WorldElement, for example). Give this class variables to store all the data you mentioned. Then give it a method which will in some way convert this information into a viewable form. For example, you could have the method create a UIImageView and pass that view the image stored in the WorldElement instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜