所以我有一个简单的客户端应用程序与node.js中的服务器端应用程序通信.在客户端,我有以下代码:
function send (name) {
http.request({
host: '127.0.0.1',
port: 3000,
url: '/',
method: 'POST'
}, function (response) {
response.setEncoding('utf8');
response.on('data', function (data) {
console.log('did get data: ' + data);
});
response.on('end', function () {
console.log('\n \033[90m request complete!\033[39m');
process.stdout.write('\n your name: ');
});
response.on('error', function (error) {
console.log('\n Error received: ' + error);
});
}).end(query.stringify({ name: name})); //This posts the data to the request
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我不通过以下方式包含'数据'事件:
response.on('data', function (data) {
console.log('did get data: ' + data);
});
Run Code Online (Sandbox Code Playgroud)
响应的"结束"事件永远不会被触发.
服务器代码如下:
var …
Run Code Online (Sandbox Code Playgroud) 我目前是OpenGL ES 2.0领域的新手,我想尽可能多地了解绑定,缓冲区,着色器等.
截至目前,我只是想了解之间的差异GL_ELEMENT_ARRAY_BUFFER
和GL_ARRAY_BUFFER
以及何时使用每个指出预设.
我目前的理解使我相信这GL_ELEMENT_ARRAY_BUFFER
是专门针对所述三角形的指数,而另一个是针对其他一切的指数.
有人可以详细说明为什么以及这是否正确?如何GL_ELEMENT_ARRAY_BUFFER
不同的处理方式?
我有下面的方法,用于检索和调用从API调用的unixTimeStamp到我可以轻松操作和使用的NSDate对象.出于某种原因,这会返回错误的值.一个例子是当unixTimeStamp是1385152832时,日期应该是
星期五,2013年11月22日20:40:31 GMT 2013年11月22日美国东部时间下午3:40:31
但反而吐出:45852-09-07 08:13:52 EST.有谁知道为什么会这样?
-(NSDate *)messageDate
{
NSTimeInterval unixTimeStamp = [[self messageDateString] doubleValue];
NSDate *messageDate = [NSDate dateWithTimeIntervalSince1970:unixTimeStamp];
NSAssert(messageDate, @"messageDate should not be nil");
return messageDate;
}
Run Code Online (Sandbox Code Playgroud)
所以我有一个基础游戏设置,可以在下面的bitbucket链接找到:
我目前很难理解如何翻译相对于场景布局的相机节点.
目标是让摄像机跟随播放器,直到达到由场景大小定义的角落边界.在此特定测试场景设置中,场景大小为1000x1000,相机比例为1.
下面的代码用于在新位置设置为跟随角色时修改摄像机的位置:
var cameraPosition: CGPoint {
get {
return CGPoint(x: camera!.position.x, y: camera!.position.y)
}
set {
let cameraScale = CGFloat(1)
let sceneScale = CGFloat(1)//CGFloat(1 - 0.44 + 0.05 /*possible rounding error adjustment*/)
// let viewAspectRatio = CGRectGetWidth(view!.frame)/CGRectGetHeight(view!.frame)
let newPositionValue = double2(x: Double(newValue.x * sceneScale), y: Double(newValue.y * sceneScale))
let scaledSceneSize = CGSize(width: size.width * sceneScale , height: size.height * sceneScale)
//// scaledSceneSize.height = scaledSceneSize.height / viewAspectRatio
let cameraSize = view!.bounds.size
let scaledCameraSize = CGSize(width: cameraSize.width * cameraScale, …
Run Code Online (Sandbox Code Playgroud) 我想拖动一个UIView,让它移动附加到其上的其他视图的位置,就像它们都是通过字符串连接一样.起始状态将是一堆UIViews聚集在一起.如果你拉出一个,它附加的项目将在它与被拖动的视图之间达到最小距离后开始移动.我认为实现这一目标的最佳方法是使用UIDynamicItemBehavior,考虑到我需要将其重新捕捉到适当位置并对其施加权重.如果不做荒谬的代码,我不太清楚如何实现这一点.我所拥有的代码可以在下面看到.不幸的是,我遇到的问题是被拖动的方形项目回到了square2.如果有人有任何建议,我会很乐意澄清是否需要.
- (void)viewDidLoad
{
[super viewDidLoad];
_containmentView = [[UIView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height/2, self.view.frame.size.width, 200)];
[self.view addSubview:_containmentView];
[_containmentView setBackgroundColor:[UIColor greenColor]];
_square = [[UIView alloc]initWithFrame:CGRectMake(200, 0, 100, 100)];
_square.backgroundColor = [UIColor yellowColor];
[_containmentView addSubview:_square];
_square2 = [[UIView alloc]initWithFrame:CGRectMake(100, 0, 100, 100)];
_square2.backgroundColor = [UIColor redColor];
[_containmentView addSubview:_square2];
_animator = [[UIDynamicAnimator alloc]initWithReferenceView:_containmentView];
_gravity = [[UIGravityBehavior alloc]initWithItems:@[_square, _square2]];
_gravity.gravityDirection = CGVectorMake(-1.0, 0.0);
[_animator addBehavior:_gravity];
_collision = [[UICollisionBehavior alloc]initWithItems:@[_square]];
_collision.collisionDelegate = self;
_collision.translatesReferenceBoundsIntoBoundary = YES; //causes the boundary to use the bounds of the reference …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个openGL引擎(ES 1.1的一侧和ES 2.0的一侧).两个引擎目前都有一些恒定的顶点(如下所示).不幸的是,在编译时我收到以下错误:
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation) with the duplicate symbol being _Verticies.
Run Code Online (Sandbox Code Playgroud)
为什么Xcode抱怨两个单独文件中的重复常量值?这些文件符合相同的协议......但大部分都是它们的连接.在C++中,此方法工作正常,但在转换为Objective-C时会引起注意到的错误.
//Define the positions and colors of two triangles
const Vertex Verticies[] = { //per vertex data
{{-0.5f, -0.866f},{1.0f, 1.0f, 0.5f, 1.0f}},
{{0.5f, -0.866f},{1.0f, 1.0f, 0.5f, 1.0f}},
{{0.0f, 1.0f},{1.0f, 1.0f, 0.5f, 1.0f}},
{{-0.5f, -0.866f},{0.5f, 0.5f, 0.5f, 0.0f}},
{{0.5f, -0.866f},{0.5f, 0.5f, 0.5f}},
{{0.0f, -0.4f},{0.5f, 0.5f, 0.5f}},
};
Run Code Online (Sandbox Code Playgroud)
解决方案:截至目前,似乎默认情况下,Objective-C中的const值受项目范围的影响,而不仅仅是文件的范围.在C++中,当创建const值时,范围自动限制在它所在的文件中.要在Objective-C中修复此问题,必须使用静态标记将范围限制为该特定文件.您也可以使用extern标签(但这会更多一点).
我确信这是一个非常愚蠢的问题,但它确实让我措手不及,可能是因为我没有正确地思考这个问题.在使用OpenGL ES 2.0时,我遇到了以下代码
/////////////////////////////////////////////////////////////////
// Forward declarations
static void SceneMeshInitIndices(
GLushort meshIndices[NUM_MESH_INDICES]);
static void SceneMeshUpdateNormals(
SceneMeshVertex mesh[NUM_MESH_COLUMNS][NUM_MESH_ROWS]);
static void SceneMeshUpdateMeshWithDefaultPositions(
SceneMeshVertex mesh[NUM_MESH_COLUMNS][NUM_MESH_ROWS]);
Run Code Online (Sandbox Code Playgroud)
现在,让我措手不及的是,函数将其输入声明为具有特定大小的2D数组.我从来没有见过这样做过,我完全不确定它是否合法或者它在Objective-C中是如何合法的.我总是被告知要使用指向原始数组的指针并将其传入.但是,这看起来很奇怪.任何人都可以尝试向我解释这一点,或指出我推断的错误是什么?
当我尝试从JSON结果中获取结果时。它引发以下异常。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString objectForKey:]: unrecognized selector sent to instance 0xa006449656c6f526'
Run Code Online (Sandbox Code Playgroud)
我的代码。
NSString *responseStringWithEncoded = [[NSString alloc] initWithData: mutableData encoding:NSUTF8StringEncoding];
id jsonObjects = [NSJSONSerialization JSONObjectWithData:
mutableData options:NSJSONReadingMutableContainers error:nil];
for (NSDictionary *dataDict in jsonObjects) {
NSString *firstname = [dataDict objectForKey:@"FirstName"];
}
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出一个NSException
。
我的JSON响应如下所示。
{
"IsExternal": 0,
"LoginId": 4,
"EmployeeId": 223,
"FirstName": "GharValueCA",
"RoleId": 4,
"LastName": null,
"Mobile": null,
"AgencyId": 100,
"BranchId": 74
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。