Using standard CPP for iOS development

问题描述:
今天在研究iPad与flash通讯。TUIO库使用标准C++(.cpp),而iPad使用OC(.m)。一调用TUIO类库就报错。

问题分析:
TUIO放入解决方案,不调用TUIO库中的内容不报错,一调用就报错。说明说连接问题,或者是不能这样调用。

问题解决
把所有.m文件改为.mm后缀,使其变为Objective-C++文件。
一切ok了。

循环引用错误

问题描述:

今天在做denizen puzzle的iPad版,Xcode有两个文件报错:

/Users/CouldHll/Desktop/Puzzle/Classes/StartButton.h:16:0 /Users/CouldHll/Desktop/Puzzle/Classes/StartButton.h:16: error: expected specifier-qualifier-list before 'StartLayer'

/Users/CouldHll/Desktop/Puzzle/Classes/StartLayer.h:16:0 /Users/CouldHll/Desktop/Puzzle/Classes/StartLayer.h:16: error: expected specifier-qualifier-list before 'StartButton'

问题分析:

仔细检查了一下,代码没有问题。检查着,突然发现这两个文件是circle reference,两个文件头都互相引用:

#import "StartLayer.h"

#import "StartButton.h"

问题解决:

一个改成@class StartLayer;

一个保持#import "StartButton.h"

一切安逸了。

函数返回值为枚举类型引起的错误

问题描述:
今天,做Denizen联手拼图iPad版,- (PlateOrientation)orientationRight读取属性函数中的return [self convertAngleToOrientation:_angleRight];报错:error: incompatible types in return

问题分析:
拆分 return [self convertAngleToOrientation:_angleRight];变为:
PlateOrientation orientation=[self convertAngleToOrientation:_angleRight];
return  orientation;
继续报错: error: incompatible types in assignment
原来问题出在 [self convertAngleToOrientation:_angleRight]上,这个应该返回enum的函数,用枚举接受其值却报错。

问题解决:
enum总是uint的,先用uint接住再转成enum:
uint uintOrientation=[self convertAngleToOrientation:_angleRight];
PlateOrientation orientation=uintOrientation;
return orientation;

PS:调用函数原型:
- (PlateOrientation)convertAngleToOrientation: (uint)vAngle

FiveDice

公司要开发一个iPhone的骰子游戏,找到一个开源的骰子项目。以下是其具体内容:

-------------------------------------------------------------------------

Yahtzee是一款暢銷的經典骰子遊戲,剛接觸時可能會丈二金剛摸不著頭腦,但只要一上手,可是會入迷的喔(我就是)。

先介紹一下玩法吧,首先進入遊戲之後在畫面上您會看到有五顆紅色的骰子,而在右上方則有一個Roll 1 of 3的紅色按鈕,而在下方會有一個計分卡(Score Card),而您要做的就是『Roll滾動骰子』然後在計分卡上選擇得分的方式,一共有12個回合,而每一個回合您可以選擇重骰或保留部份的骰子,最多可以再擲骰三次,每一次回合結束一定要選擇一種得分方式,而每一種得分方式只能夠選擇一次,而您的分數會出現在右下角的Score旁邊。

計分卡的得分方式分別有:

Aces                五顆骰子中點數為1的加總得分。
Twos                同Aces,但為點數2的加總得分。
Threes             同Aces,但為點數3的加總得分。
Four                 同Aces,但為點數4的加總得分。
Fives                同Aces,但為點數5的加總得分。
Sixes                同Aces,但為點數6的加總得分。

如果您擲 1,2,2,3,5,若選擇Aces計分則得到的分數為1分,若選擇2則得到分為為4分。

3 of a kind        三個相同點數。
4 of a kind        四個相同點數。
Full House        三個1兩個6。
Sm Straight      1,2,3,4 各一個。
Lg Straight       1,2,4,5,5各一個。
Yahtzee            五個5。

以上這幾種在畫面中都有圖示說明,跟著擲出相同的骰型就可以得分。

Chance            五顆點數全部加總。

站長在寫各項軟體說明的過程中竟然能發現這麼好玩的遊戲,這也算是另一種意外的收穫吧,iPhone實在太有趣了。

聯絡資訊:iphone@conceitedsoftware.com
檔案位置:http://conceitedsoftware.com/iphone/zips/FiveDice.zip
程式維護:Conceited Software
安裝來源:http://conceitedsoftware.com/iphone/
官方網站:http://code.google.com/p/5dice

cocos2d

cocos2d for iPhone is a framework for building 2D games, demos, and other graphical/interactive applications.

http://www.cocos2d-iphone.org/

http://www.learn-cocos2d.com/

http://code.google.com/p/cocos2d-iphone/

以下是教程:

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index

http://www.cocoachina.com/bbs/read.php?tid-15554.html

http://www.bit-101.com/blog/?p=2115

http://monoclestudios.com/cocos2d_whitepaper.html

http://www.ezshine.cn/blog/index.php/archives/297

iPhone开发资源

iPhone Developer Program:http://developer.apple.com/programs/iphone/

官方视频教程:http://developer.apple.com/iphone/index.action

31天学会iPhone开发:http://www.ezshine.cn/blog/index.php/archives/154

Learn Objective-C:http://cocoadevcentral.com/d/learn_objectivec/

斯坦福iPhone编程课程iPhone Application Programming:http://itunes.stanford.edu/

斯坦福大学公开课(部分翻译):http://v.163.com/special/opencourse/iphonekaifa.html

西蒙iphone-OpenGL ES 教程:http://www.cocoachina.com/bbs/read.php?tid-7086.html

Unity3D:http://unity3d.com/

Cocoa苹果开发中文站:http://www.cocoachina.com/