小黑米的生活

只玩技术

Archive for the ‘技术’ Category

nohup 命令使用注意

leave a comment

nohup命令作用:让进程在后台可靠运行

nohup 的一般用法(命令行下):

nohup command > command.log 2>&1 &

如果终端推出或网络断开,会向进程发送hangup信号~ 如果进程没有特殊处理hangup默认是忽略的~ 进程会被挂到init进程下,从而可以在后台继续执行

继续阅读

Written by edwardhey

一月 30th, 2012 at 9:39 下午

Posted in 技术

[Javascript] 原型(prototype)实现面向对象

leave a comment

使用JS原型(prototype)来做面向对象,模块化部分代码~

今天和同事讨论了下prototype,我个人比较倾向于把部分逻辑放到前端实现,从而减少对后端数据的耦合,相当于在做富客户端应用,如果这么做就必须要在客户端用面向对象编程来处理模块,但同事也很在理,一是兼容性的考虑,二是如果只是web应用或简单的web game似乎真没多少逻辑会放到浏览器去渲染的~ 好吧,不管如何也好~ 先探讨,用来做做小应用来玩着先吧~
继续阅读

Written by edwardhey

十一月 22nd, 2011 at 6:29 下午

Posted in 技术

[shell] VPN回公司环境设置正确的路由表

one comment

好吧…为了赶上工作的进度,不得不在家工作了~ 因公司的环境在内网,需要vpn回去公司环境,登陆开发机器,工作才能继续

先自己vpn回去,这个就不说了…网上有很多教程,自己google下吧~

主要还是路由表的问题~ 我网络的情况是:
ip -> gateway
192.168.5.2 192.168.5.1

公司的情况:
开发机器的ip:192.168.1.x
vpn接入的虚拟ip:x.x.x.x

所以要添加一条 192.168.1.x 的路由走 ppp0 网卡,即可实现我的需求了

#!/bin/bash
route -nv add -net 192.168.1 -interface ppp0

继续阅读

Written by edwardhey

十月 29th, 2011 at 12:39 上午

Posted in 技术

[cocos2d] 游戏里面的场景过渡

leave a comment

1. scene: OtherScene
2. init: <OtherScene = 066B2130 | Tag = -1>
3. onEnter: <OtherScene = 066B2130 | Tag = -1>
4. // 这里运行了过渡效果
5. onExit: <FirstScene = 0668DF40 | Tag = -1>
6. onEnterTransitionDidFinish: <OtherScene = 066B2130 | Tag = -1>
7. dealloc: <FirstScene = 0668DF40 | Tag = -1>

上面的是cocos2d里面的场景过渡日志,可以发现很有趣的,A场景过渡到B场景的时候,A场景发起replaceScene请求,就init B场景,然后执行B场景的onEnter函数,程序执行到这里,就说明B场景init完成,然后对A场景执行onExit和dealloc请求,最后请求A场景的onEnterTransitionDidFinish,这样就完成了2个场景

继续阅读

Written by edwardhey

十月 6th, 2011 at 7:45 上午

Posted in 技术,游戏

[cocos2d] OpenGL draw base functions

leave a comment

-(void) draw
{
CGSize s = [[CCDirector sharedDirector] winSize];

// draw a simple line
// The default state is:
// Line Width: 1
// color: 255,255,255,255 (white, non-transparent)
// Anti-Aliased
glEnable(GL_LINE_SMOOTH);

ccDrawLine( ccp(0, 0), ccp(s.width, s.height) );

// line: color, width, aliased
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
glDisable(GL_LINE_SMOOTH);
glLineWidth( 5.0f );
glColor4ub(255,0,0,255);
ccDrawLine( ccp(0

//以下被省略了…

继续阅读

Written by edwardhey

十月 6th, 2011 at 12:04 上午

Posted in objective-c,技术

[cocos2d] CCTransitionScene

leave a comment

CCTransitionScene – 所有过渡效果的基类

//淡入淡出
CCFadTransition *tran = [CCFadTransition transitionWithDuration:1
scene:[HelloWorld scene]
withColor:ccWHITE];

[[CCDirector sharedDirector] replaceScene:tran];
CCFadTransition: 淡入淡出到一个指定颜色,然后再回来
CCFadTRTransition(3):瓦片(tiles)反转过来提示场景
CCJumpZoomTransition:场景跳动着变小时,新场景则跳动着变大
MoveInLTransition(3):场景移出,同时新的场景从左(3)移入.

CCOrientedTransitionScene(6):

//以下被省略了…

继续阅读

Written by edwardhey

十月 5th, 2011 at 9:16 下午

Posted in 技术,游戏

[cocos2d] cocos2d里面一些实用的东西

leave a comment

允许屏保

[self setScreenSaverEnabled:YES];
#pragma mark Reset Game
// The game is played only using the accelerometer. The screen may go dark while playing because the player
// won’t touch the screen. This method allows the screensaver to be disabled during gameplay.
-(void) setScreenSaverEnabled:(bool)enabled
{
UIApplication *thisApp = [UIApplication sharedApplication];
thisApp.idleTimerDisabled = !enabled;
}

启用重力感应

self.isAccelerometerEnabled = YES;

启用触摸屏

self.isTouchEnabled = NO;

foreac


//以下被省略了…

继续阅读

Written by edwardhey

十月 5th, 2011 at 8:32 下午

Posted in objective-c,技术

[cocos2d] schedule

leave a comment

在处理Sprite的时候,需要设置Sprite的行为,需要使用到schedule,第一个参数就是selector对象,额~ 理解成C语言的函数指针就对了~

[self unschedule:@selector(spidersUpdate:)];
[self schedule:@selector(spidersUpdate:) interval:3.0f];
[self scheduleUpdate];//==[self scheduleUpdate:@selector(update:) interval:0.0f];

继续阅读

Written by edwardhey

十月 4th, 2011 at 10:04 下午

Posted in 技术,游戏

[cocos2d] CCArray类

leave a comment

你可 以在Xcode项目中的cocos2d/Support组找到CCArray的类文件。cocos2d引擎内 部使用了CCArray。它和苹果官方的NSMutableArray类似,但是运行效率更高。 CCArray类实现了NSArray和NSMutableArray的子集,并且添加一些从NSArray初 始化到CCArray的新方法。CCArray通过将数组中的最后一个对象(nil)赋值给删 除的位置,实现了fastRemoveObject和fastRemoveObjectAtIndex两个方法。避 免了复制部份数组的内存。这让删除数组中的元素变的更快,不过这也意味着 CCArray中的对象会改变位置。如果你的程序依赖于指定的对象排列次序,你就 不应该使用fastRemoveObject这类方法。在列表4-9中,你可以看到CCArray的 类引用 – 它没有实现所有的NSArray和NSMutableArray方法:
列表4-9. CCArray的类引用

+ (id) array;
+ (id) arrayWithCapacity:(NSUInteger)capacity; + (i

//以下被省略了…

继续阅读

Written by edwardhey

十月 4th, 2011 at 4:56 下午

[cocos2d] 加速计的使用

leave a comment

以下代码使用了三个新的“设计参数”:减速度 速率,加速计敏感度和最大速度。

减速是通过降低当前速度值来实现的。在降低速度值以后,要将新的加速度值和加速计敏感度值相乘所得的值与降低后的速度值相加。减速度速率越小,主角精灵就能越快的改变蜘蛛的方向。加速计敏感度的值越大,主角精灵对加速计的输入就越敏感。因为这三个参数一起影响着同一个值,所以在调整的时候要注意每次只调整一个值。

在layer的init加入

[self scheduleUpdate];

player是玩家的精灵,playervelocity

-(void) update:(ccTime) delta
{
CGPoint pos = player.position;
pos.x += playervelocity.x;

CGSize screenSize = [[CCDirector sharedDirector] winSize];
float imageWidthHalved = [player texture].contentSize.width*0.5f;
float le

//以下被省略了…

继续阅读

Written by edwardhey

十月 4th, 2011 at 4:23 下午

Posted in 技术,游戏