TommyT39
TommyT39

Reputation: 117

IOS 3d for the experts

I've developed a few simple iOS apps, and I'm looking to develop a simple maze game. What I'm looking to do is really basic, so I'm looking for some guidance on which way to go.

Here is basically what I'm trying to do: simple escape-the-maze game where I read in a 2 dimensional array and that makes my maze.

I want the perspective to be standing in the middle of each square, and when you flick or hit a button, it will advance one square, and you can turn left or right. I'd like to be able to apply textures to the ways based on the numbers in the array, and I'd really like to see the movement of the wall moving towards me then stop.

The walls will always be the same height, and the maze will be simple square blocks, although I do want it to be able to hand rooms that might be more than 2x2 , like maybe 4x4, and be able to handle rendering that.

I'm not sure if trying to do something in OpenGL would be overkill since my requirements are really basic. Like I mentioned, it won't be a free move; it will be advance one square each time you hit a button and turn left or right.

I have read something about ray casting for this sort of thing but am not sure how I would accomplish this in iOS. Also I'd like to have the maze not take up the whole screen, maybe 2/3, while the rest is standard iOS controls like buttons and labels, and a background behind it.

What books or articles should I read to help me? I'd prefer not to use a 3rd party engine since this seems really basic.

Upvotes: 0

Views: 1078

Answers (1)

Nick Lockwood
Nick Lockwood

Reputation: 40995

You can do this using Core Animation, which is much easier than OpenGL. If you import QuartzCore into your project, you can position any view in 3D as follows:

//set the view's 2D position so that the vanishing point is the middle
//of the screen - use the same centre for every view
view.center = CGPointMake(window.bounds.size.width / 2.0f, window.bounds.size.height / 2.0f);

//create a 3d transform
CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0f/500.0f; // this sets the 3D perspective

//you can transform the view in 3D relative to the camera
//this rotates the view by 45 degrees about the Y axis
//but you can also scale, translate, etc using equivalent functions
transform = CATransform3DRotate(transform, M_PI_4, 0.0f, 1.0f, 0.0f)

//transform the view in 3D
view.layer.transform = transform;

So if you create your walls as UIImageViews, you can arrange them into a room by transforming each one individually using the logic above.

Upvotes: 3

Related Questions