English 中文(简体)
从主游戏中创建类和内嵌
原标题:Create a class and init from main game offSet

我在做我的游戏, 我有一个如此艰难的时间 环绕着我的头 围绕一个概念,也许你可以 帮我澄清它。

So in the bullet class i create a bullet object at point 0,0 which is fine then when i really create it from the main game i create it at point

平面位置.x, 0

将它置于玩家所在的 X 轴上,而 Y 轴上为屏幕底部的 Y 0 轴上

My issue is lets say i want to create the bullet at the top of the gun for example. not at the base of the screen. so i would write thePlayer.position.x,60; it would start it at the top of the gun but there would be a offset of 60 till it hits the target... i did come up with a solution but i don t like it. I think there has to be a better answer..

my answer is: make a var call bulletOffet=any number lets say 60 then create the bullet at thePlayer.position.x, 0+bulletOffSet

现在,当我检查我 子弹和目标

for (Bullet *someBullet in self.children) { if ([someBullet isKindOfClass:[Bullet class]]) { CGPoint bulletPoint = CGPointMake(someBullet.position.x, someBullet.bulletSprite.position.y+bulletOffSet);

this does work but again there has to be a better solution let me know what i m missing thank you

问题回答

你的问题应该能够通过改变子弹的锚点来解决

我理解锚点能帮助你解决问题。我下面附上了一个链接,可以很好地了解锚点如何运作。

http://www.qcmat.com/underad-anchorpoint-in-cococs2d/" rel="no follow" >http://www.qcmat.com/underadate-anchorpoint-in-cococs2d/





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签