我已经忙了几天试图找出如何在我的Cocos2d项目中处理触摸.情况与正常情况有点不同.我有几个不同的游戏图层,上面有我需要通过触摸控制的项目:
现在我在ControlLayer中工作得很好,我可以移动我的可玩角色并让他跳跃并做其他愚蠢的事情.然而,我无法掌握如何实现我的一些CCSprites的触摸.
到目前为止我收集的信息让我觉得我需要从控制层获取所有触摸输入.然后我不知何故需要将触摸信息"级联"到GameplayLayer,以便我可以在那里处理输入.另一种选择是让我通过某种方式创建一个指向应该可触摸的对象的指针来从我的精灵中获取CGRect信息.我应该能够在ControlLayer中使用该信息来检查该项目中每个项目是否被触摸.
这样做的最佳选择是什么,我该如何实现?我对使用cocoa和Objective C进行编程有点新意,所以我不确定这个语言的最佳选择是什么,以及如何在另一个类中访问sprite CGRect信息([mySpriteName boundingBox])然后是它的层呈现在.
目前,我确定让它工作的唯一方法是为每个CCSprite位置创建重复的CGRects,因此我可以检查它们,但我知道这不是正确的方法.
我到目前为止(测试)是这样的:ControlLayer.m
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
CGRect rect = CGRectMake(0.0f, 0.0f, 100.0f, 100.0f);
//Tried some stuff here to get see if I could get a sprite by tagname so I could use it's bounding box but that didn't work
// Check for touch with specific location
if (CGRectContainsPoint([tree boundingBox], location)) {
CCLOG(@"CGRect contains the location, touched!");
} …Run Code Online (Sandbox Code Playgroud) 我现在搜索了大约一个小时,发现了大量的问题,描述了如何向Devise用户模型添加字段.但是,我找不到任何明确解释如何在注册过程中添加一个或多个模型的方法.
在注册时,我希望用户填写电子邮件地址,密码以及我的客户端模型,公司模型和地址模型(因此我拥有web应用程序正常运行所需的所有信息).
我的模特是这样的
user.rb
Run Code Online (Sandbox Code Playgroud)class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :email, :password, :password_confirmation, :remember_me, :client belongs_to :client end
client.rb
Run Code Online (Sandbox Code Playgroud)class Client < ActiveRecord::Base attr_accessible :bankaccount, :email, :logo, :mobile, :phone, :website has_many :users has_one :company has_one :address accepts_nested_attributes_for :company, :address end
我认为唯一的方法是创建我自己的RegistrationsController,这样我就可以@client = Client.new在我的视图中执行此操作:
Run Code Online (Sandbox Code Playgroud)<%= f.simple_fields_for @client do |ff| %> <%= f.simple_fields_for :company do |fff| %> <% field_set_tag t(:company) do %> <%= ff.input :name %> <% end %> <% end %> <%= f.simple_fields_for …