我已经建立了一个小的ipad游戏,spritesheets和batchnodes到处都是.但是我不知道它们是如何工作的,何时添加精灵表,何时将sprite添加到spritebatchnode等.
这是我在初始屏幕(主菜单)中所做的:
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"sprites.png"];
screenSize = [CCDirector sharedDirector].winSize;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sprites.plist"];
[self addChild:spriteSheet];
Run Code Online (Sandbox Code Playgroud)
在其他类 - 我总是需要使用相同的批处理节点 - >"sprites.png" - 我打电话
CCSprite *someSprite = [CCSprite spriteWithSpriteFrameName:someSpriteFrameName.png];
Run Code Online (Sandbox Code Playgroud)
并将其添加到self
.
[self addChild:someSprite]; // I do not understand why I would add my sprite to the batch node instead of self
Run Code Online (Sandbox Code Playgroud)
所以情况如下:
我有一个名为"sprites.png"的文件,我所有的精灵都在这里.
我似乎并没有完全掌握这个概念.我知道为什么使用它.但是如果有人能够以外行的方式再次向我解释一切,我真的很感激,所以我对我所做的事情100%肯定.请尝试解释它是基本的.
我有一个UIScrollView,在其中添加了子视图。scrollview垂直滚动良好,这就是它应该做的。现在,我想借助UISwipeGestureRecognizer识别子视图中的向左/向右滑动。我知道这是有可能的,但是我没有找到解决方案,并且几次尝试都没有成功。
由于喷油器没有正确喷射,我对单元测试angularJS有困难.我注入的任何东西都是undefined
.
模块:
app.module.js
angular.module('myServices', []);
Run Code Online (Sandbox Code Playgroud)
AngularTest.js
describe('AngularTest', function() {
beforeEach(module('myServices'));
var scope;
beforeEach(inject(function(_$rootScope_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
scope = _$rootScope_;
}));
describe('Testing Angular injection', function() {
it('scope should be defined', function() {
expect(scope).toBeDefined(); // fails
});
});
});
Run Code Online (Sandbox Code Playgroud)
我已经在我的主模块中成功测试了控制器,但是,这个特定的模块正在测试我的理智.
有任何想法吗 ?
业力文件:
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-animate/angular-animate.js',
'app/bower_components/angular-cookies/angular-cookies.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/app.module.js',
'app/components/**/controller/*.js',
'app/components/**/model/*.js',
'app/components/**/test/unit/*.js'
]
Run Code Online (Sandbox Code Playgroud)
服务模块定义在app.module.js
,服务在app/components/services/model/myService.js
(路径似乎不合逻辑,我试图抽象我的结构尽可能概括这个问题)
Karma似乎也没有抱怨:从日志中:
28 08 2015 03:38:47.095:WARN …
Run Code Online (Sandbox Code Playgroud) 我想在我的Mac应用程序中实现一些"简单"的拖放操作.我在视图中拖动并相应地在我的nib文件中输入"MyView".但是我的控制台中没有得到任何响应(我尝试在触发任何协议方法时记录消息)
我有这样的NSView子类:
@interface MyView : NSView <NSDraggingDestination>{
NSImageView* imageView;
}
Run Code Online (Sandbox Code Playgroud)
并像这样实现它:
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self registerForDraggedTypes:[NSImage imagePasteboardTypes]];
NSRect rect = NSMakeRect(150, 0, 400, 300);
imageView = [[NSImageView alloc] initWithFrame:rect];
[imageView setImageScaling:NSScaleNone];
[imageView setImage:[NSImage imageNamed:@"test.png"]];
[self addSubview:imageView];
}
return self;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender{
NSLog(@"entered");
return NSDragOperationCopy;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender{
return NSDragOperationCopy;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender{
NSLog(@"exited");
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender{
NSLog(@"som");
return YES;
}
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
NSPasteboard *pboard = [sender draggingPasteboard]; …
Run Code Online (Sandbox Code Playgroud) 我现在正在开发游戏一段时间,我通过反复试验与convertToWorldSpace合作.它总是很有效,但我不知道我要做的是说实话.我真的很讨厌我不明白我在做什么,但遗憾的是互联网并没有提供有关这个问题的更多信息.所以我希望有人可以解释一下,为什么我必须从节点的父节点调用convertToWorldSpace,以及当我使用convertToNodeSpace时.我完全没有头绪.有人可以解释一下他们做了什么,也许可以举个例子吗?我真的很感激!:-)
我想让这个类通过向它传递不同的名称来动态地执行函数.那可能吗 ?或者更确切地说:它怎么可能?
-(id)initWithMethod:(NSString*)method{
if ((self = [super init])){
[self method];
}
return self;
}
-(void) lowHealth {
CCSprite *blackScreen = [CCSprite spriteWithFile:@"blackscreen.png"];
blackScreen.anchorPoint = ccp(0,0);
[self addChild:blackScreen];
id fadeIn = [CCFadeIn actionWithDuration:1];
id fadeOut = [CCFadeOut actionWithDuration:1];
id fadeInAndOut = [CCRepeatForever actionWithAction:[CCSequence actions:fadeIn, fadeOut, nil]];
[blackScreen runAction:fadeInAndOut];
}
Run Code Online (Sandbox Code Playgroud) 我有两个Maven项目.其中一个必须依赖另一个.我使用IntelliJ,我试图右键单击project1>打开模块设置,并在依赖项选项卡中单击+符号以添加目录或jar依赖项.到目前为止一切顺利,当我尝试从依赖项中导入包时,它会为我自动填充它,但是编译会抛出错误,说没有这样的包.我究竟做错了什么 ?
我想要实现一些非常简单的事情.我想改变一个层的规模.但它似乎没有按预期工作.事实上,它根本不起作用.图层的比例保持不变.
这是我的代码:
NSView *v = [[NSView alloc]init];
v.wantsLayer = YES;
v.frame = self.bounds;
float scale = 0.8f;
[v.layer setAffineTransform:CGAffineTransformMakeScale(scale,scale)];
[self addSubview:v];
Run Code Online (Sandbox Code Playgroud)
如果我记录我获得的affineTransform
属性.v
null
我正在尝试使用自定义序列化程序来处理序列化程序中的关系并启用json_api适配器.但是,关系没有正确序列化(或者更好,完全没有显示/序列化).
PostController.rb
def index
render json: Post.all, each_serializer: Serializers::PostSerializer
end
Run Code Online (Sandbox Code Playgroud)
串行
module Api
module V1
module Serializers
class PostSerializer < ActiveModel::Serializer
attributes :title, :id
belongs_to :author, serializer: UserSerializer
has_many :post_sections, serializer: PostSectionSerializer
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
JSON输出:
{
"data": [
{
"attributes": {
"title": "Test Title"
},
"id": "1",
"relationships": {
"author": {
"data": {
"id": "1",
"type": "users"
}
},
"post_sections": {
"data": [
{
"id": "1",
"type": "post_sections"
}
]
}
},
"type": "posts"
}
]
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,关系未得到满足, …
我已经在objective-c中编程了一年多一点,而且我总觉得使用@property和@synthesize这是一个惯例.但他们真正服务的目的是什么?他们是否只是在课堂之间进行沟通?因此,例如,如果我仅在声明它的类的范围内使用NSMutableDictionary,那么遗漏是否正常?
另一个问题:
如果我设置NSMutableDictionary的属性,它会被保留,对吧?所以,在我的课上我不必调用alloc()和init(),是吗?使用属性的规则是什么?
objective-c ×5
iphone ×4
ipad ×3
ios ×2
angularjs ×1
cocoa ×1
dependencies ×1
javascript ×1
json ×1
macos ×1
maven ×1
properties ×1
ruby ×1
sprite-sheet ×1
uiscrollview ×1
unit-testing ×1
xcode ×1