2

I have to develop an app that has to present a "floor" of hexagons in "The Sims" style, something like this, but simpler.

I really know little or nothing about CoreGraphics and absolutely nothing about OpenGL, which way you would use to do the job in a "easy" and "quick" way?

IssamTP
  • 2,408
  • 1
  • 25
  • 48
  • 3
    Does the floor need to be a real 3d space with a movable camera and other things in the 3d world? Or is it a fixed image/perspective? If the former, there's no "trivial" 3d, you'll likely need GL. If you need something quite simple and fixed, CG will be much easier to do. – Ben Zotto Feb 17 '12 at 20:07
  • Uhm, in a first moment I guess I don't have to move the floor, but I bet that will be the next step... – IssamTP Feb 17 '12 at 20:40

3 Answers3

1

You should have a look at Cocos2D. It makes programming games like that much easier. It also supports tile maps, that you can use to create the floor.

sch
  • 27,436
  • 3
  • 68
  • 83
1

Try using CATransform3D to apply perspective to your 2D views. Related Question: How do I apply perspective?

Community
  • 1
  • 1
Jason Harwig
  • 43,743
  • 5
  • 43
  • 44
1

There are myriad ways to achieve this. As I read it, you're looking for a 2D perspective, which thankfully is far more accessible for anyone without experience with 3D rendering. You could explore the use of a 3rd party library as sch suggested.

If you wanted a "native" solution, your options are going to be either something CG based or something image/UIKit based. Both are relatively accessible.

With Quartz/CG, essentially you will draw series of lines and arcs to compose the shapes you want. I generally create sketches on paper, then kind of plot out the rough segments and components I need in code; it's really not very hard to draw the paths with CG commands. You can build a shape-factory class pretty easily, and then you can just ask that for a given shape in a given size when it comes time to drop a shape into your view.

If you're reluctant to draw the paths in code, your last option is to use UIKit. With this approach, you could create your shapes in photoshop, slice them into images, then place those into imageviews and into your app. You can then manipulate these images in 2.5d space using CALayer transforms. If your needs are modest, this is a relatively easy and simple way to do it and have it look decent. Unfortunately this approach is not highly dynamic, wouldn't scale well, and may simply not meet with the performance threshold you're looking for on-screen.

isaac
  • 4,867
  • 1
  • 21
  • 31
  • I don't think that UIKit will fit my needs, because my tiles must be "clickable" (should I tell tapable?)... – IssamTP Feb 17 '12 at 20:37
  • If you're using images presented on UIImageViews, those fully support all interaction/touch events. If you end up transforming those images with CALayers, you loose a lot of interaction, but you can still use a layer hitTest to determine if a given image/layer was tapped. – isaac Feb 17 '12 at 20:40
  • I'd add, if you can do with just a 2d views, eg, like looking down at a room laying out furniture, then you can just put each shape in it's own imageview, and the user can then drag those images or tap them very easily. – isaac Feb 17 '12 at 20:42
  • So, let's say that you have to draw a floor let's say 10 tiles x 10 tiles, you would use a set of 100 image view where I draw programmatically the hexagons? – IssamTP Feb 17 '12 at 20:53
  • You can make a pattern image of a single tile (eg, one hexagon), with [UIColor colorWithPatternImage:[UIImage imageNamed:@"oneHex"]], then apply that as a background color to a view of whatever size you wish. – isaac Feb 17 '12 at 21:41
  • That's nice, but I guess that then I can't tap one by one or am I wrong? More i need to place the hexagonal tiles in... bee way, something like http://3.bp.blogspot.com/_UNJrX0YYHuo/TTuDEuGa8nI/AAAAAAAAASw/dAc0r-WwUoc/s1600/Tassellatura+esagonale.png . – IssamTP Feb 18 '12 at 09:59