小黑米的生活

只玩技术

Archive for the ‘技术’ Category

[cocos2d] cocos2d 1.0 设置屏幕默认为纵向

leave a comment

在RootViewController.m里面,在shouldAutorotateToInterfaceOrientation:方法里面,找到这个宏判断

#elif GAME_AUTOROTATION == kGameAutorotationUIViewController

然后把

return (UIInterfaceOrientationIsLandscape(interfaceOrientation));

改成

return (UIInterfaceOrientationIsPortrait(interfaceOrientation));

继续阅读

Written by edwardhey

十月 4th, 2011 at 1:22 下午

Posted in objective-c,游戏

[cocos2d] 游戏开发基础概念

leave a comment

场景(CCScene)
每个场景都是通过不同的局(Layer)的叠加和组合协作来实现丌同的功能的。因此,通常每个场景都是有一个戒者几个局组成的。

场景(CCScene)
层是我们写游戏的重点,我们大约 99%以上的时间是在局上实现我们游戏内容。层有叠加顺序,最上层的将会最先响应时间,如果有一个层处理了该时间,则排在后面的层讲不再接收到该时间

精灵(CCSprite)
精灵是整个游戏开发处理的主要对象,地方的飞机、坦克是系统AI控制的精灵。

导演(CCDirector)
导演负责游戏全过程的场景切换,通常只有一个。

继续阅读

Written by edwardhey

十月 3rd, 2011 at 11:41 下午

Posted in objective-c,游戏

[WordPress插件] 截取字符,文章摘要(支持html)

leave a comment

最近在倒腾一个wordpress插件,截取字符,用于显示文章摘要,并支持html截断…非常适合做摘要使用~

效果请见 [Object-C] 数据结构

继续阅读

Written by edwardhey

九月 18th, 2011 at 6:21 上午

[Object-C] 指针函数

leave a comment

//
// main.m
// obc
//
// Created by edward yang on 11-6-12.
// Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

int lookup (void){
return 1;
}

int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

//声明为函数指针
int (*fnPtr) (void);
fnPtr = lookup;

NSLog(@“%d,fnPtr());

[pool drain];
return 0;
}

继续阅读

Written by edwardhey

六月 16th, 2011 at 11:15 上午

Posted in objective-c

[Object-C] 常量

leave a comment

预处理程序对宏定义的参数实行文本替换,要避免一些有趣的陷阱

#define SQUARE(x) x*x;
y=SQUARE(v); //work fine;
y=SQUARE(v+1); //这样会造成和期望不一样的结果,因为会执行这样 y= x+1*x+1;
#define SQUARE(x) ((x)*(x)); //这样的更改是正确的,而且非常重要, 尤其是外面的括号~
#define IS_LEAP_YEAR(y) y%4==0 && y%100!=0 \
||y%400==0

继续阅读

Written by edwardhey

六月 15th, 2011 at 11:42 上午

Posted in objective-c

[Object-C] 数据结构

one comment

枚举类型:

enum direction {east,west,south,north};//定义枚举
enum direction dir;//声明变量

enum {east,west,south,north} direction;//定义枚举并声明变量,注意作用域…

typedef enum {east,west,south,north} Direction;//定义Direction类型是枚举类型的,注意和上面的语法不同,typedef ,所以理解成 typedef enum {east,west,south,north} Direction;

字符对象

//字符串替换
[mstr replaceOccurrencesOfString:search withString:replace options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mstr length])];

//从文件读入内容,并创建字符串
NSString* pat

//以下被省略了…

继续阅读

Written by edwardhey

六月 11th, 2011 at 9:08 上午

Posted in objective-c

巧妙的注释

leave a comment

没有想不到只有做不到

//*
do_test();
/*/
do_prod();
//*/

继续阅读

Written by edwardhey

五月 27th, 2011 at 1:27 下午

Posted in 技术

[Object-C]面向对象小试牛刀

leave a comment

XYPoint.h

//
// Rectangle.h
// study
//
// Created by edwardhey on 11-5-25.
// Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

@class XYPoint; //相当于占位符,编译的时候会载入XYPoint类而不至于载入整个头文件,以保证下面的代码可以继续编写,这种效率会更好,如果要使用类里面的方法的时候就必须把整个头文件载入
@interface Rectangle : NSObject {
int width;
int height;
XYPoint *origin;
}

@property int width, height;

-(XYPoint *) origin; //相当于getter , .方式访问会访问此函数
-(void) setOrigin: (XYPoint*) pt; //相当于setter
//以下被省略了…

继续阅读

Written by edwardhey

五月 25th, 2011 at 6:11 下午

Posted in objective-c,技术

获取某目录下所有文件的大小

leave a comment

获取source目录下面所有文件的大小(字节)

du ./source

获取source目录下面所有文件的大小(字节),但不计算.svn的特殊文件

find ./source -name [^.]* -type f|grep -v .svn|xargs ls -l |awk BEGIN{size=0}{size+=$5}END{print size}

继续阅读

Written by edwardhey

五月 25th, 2011 at 5:33 下午

Posted in 技术

[Git] 配置使用

leave a comment

配置文件

$ cat ~/.gitconfig
[user]
name = Edward.yang
email = git@git.com
user = edwardhey
[github]
user = edwardhey
token = e897aae57f5928966ef93873ef551c87
[color]
diff = auto
status = auto
ui = auto
branch = auto
[alias]
ci = commit
co = checkout
up = reset –hard
[diff]
tool = vimdiff
[difftool "vimdiff"]
cmd = vimdiff
[difftool]
prompt = false

首先在服务端配置git纯净版本库

$ cd /data/gi
//以下被省略了…

继续阅读

Written by edwardhey

五月 19th, 2011 at 3:36 下午

Posted in 技术