我正在制作一个 2d 横向卷轴。
有从右边产生的火箭。
当我向一个人投掷弹丸时,我希望它:
下面是我一直试图开始工作的代码,我对哪个节点是哪个节点以及如何定位两个不同的节点感到困惑...... bodyA 和 bodyB 执行同样的事情也非常低效...
这一切都在
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | if contact.bodyA.categoryBitMask == rocketgroup || contact.bodyB.categoryBitMask == rocketgroup { //projectileObject.physicsBody?.velocity = CGVectorMake(0 , 0) if Model.sharedInstance.sound == true { runAction(RocketExplosionPreload) } Model.sharedInstance.totalscore = Model.sharedInstance.totalscore + Model.sharedInstance.score RocketExplodeTexturesArray = [SKTexture(imageNamed:"RocketExplode0"),SKTexture(imageNamed:"RocketExplode1"),SKTexture(imageNamed:"RocketExplode2"),SKTexture(imageNamed:"RocketExplode3"),SKTexture(imageNamed:"RocketExplode4"),SKTexture(imageNamed:"RocketExplode5"),SKTexture(imageNamed:"RocketExplode6")] let RocketExplodeAnimation = SKAction.animateWithTextures(RocketExplodeTexturesArray, timePerFrame: 0.1) let RocketExp = SKAction.repeatAction(RocketExplodeAnimation, count: 1) print(contact.bodyA.node) print(contact.bodyB.node) if let node = contact.bodyA.node as? SKSpriteNode { print(node) //node.paused = true if node.parent != nil { let moveUp = SKAction.moveToY(0, duration: 1) let fadeOut = RocketExp let remove = SKAction.removeFromParent() let moveAndFade = SKAction.group([moveUp, fadeOut]) let sequence = SKAction.sequence([moveUp,fadeOut]) RocketNode?.runAction(sequence) { /// remove theSprite from it's parent /// Might need to weakly reference self here RocketNode!.removeFromParent() ProjectileNode!.removeFromParent() print("Deleted") } //node.removeFromParent() } } if let node = contact.bodyB.node as? SKSpriteNode { print(node) //node.paused = true if node.parent != nil { let moveUp = SKAction.moveToY(0, duration: 1) let fadeOut = RocketExp let remove = SKAction.removeFromParent() let moveAndFade = SKAction.group([moveUp, fadeOut]) let sequence = SKAction.sequence([moveUp,fadeOut]) RocketNode?.runAction(sequence) { /// remove theSprite from it's parent /// Might need to weakly reference self here RocketNode!.removeFromParent() ProjectileNode!.removeFromParent() print("Deleted") } } } } |
就像@whirlwind 评论的那样,您在这里同时提出了很多问题。
我还没有运行此代码,但它肯定会为您指明正确的方向。
2 3 4 5 6 7 8 | { var HP: Int = 10 func runHitAnimation() { // flash red or something } } |
检测联系人:
2 3 4 5 6 7 8 9 10 11 12 13 14 | let rocketCategory: UInt32 = 8 func didBeginContact(contact: SKPhysicsContact) { let firstBody = contact.bodyA let secondBody = contact.bodyB if (firstBody.categoryBitMask | secondBody.categoryBitMask) == (projectileCategory | rocketCategory) { self.evaluateRocketProjectileContact(between: firstBody, and: secondBody) } } |
评估联系人:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | { var rocketBody: SKPhysicsBody var projectileBody: SKPhysicsBody if (firstBody.categoryBitMask & projectileCategory) > 0 { projectileBody = firstBody rocketBody = secondBody } else { projectileBody = secondBody rocketBody = firstBody } let rocket = rocketBody.node as! RocketNode let projectile = projectileBody.node as! SKSpriteNode rocket.HP -= 1 // move projectile to rocket and remove its physics body projectile.moveToParent(rocket) projectile.physicsBody = nil if rocket.HP == 0 { // do something explosive animation let explode = SKAction.scaleBy(2.0, duration: 1.0) rocket.runAction(explode, completion: { rocket.removeFromParent() }) } } |
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否
Unity自动旋转动画1.开门需要门把手先动,门再动2.关门需要门先动,门把手再动3.中途播放过程中不可以再次进行操作觉得太复杂?查看我的文章开关门简易进阶版效果:如果这个门可以直接打开的话,就不需要放置"门把手"如果门把手还有钥匙需要旋转,那就可以把钥匙放在门把手的"门把手",理论上是可以无限套娃的可调整参数有:角度,反向,轴向,速度运行时点击Test进行测试自己写的代码比较垃圾,命名与结构比较拉,高手轻点喷,新手有类似的需求可以拿去做参考上代码usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;u
//1.验证返回状态码是否是200pm.test("Statuscodeis200",function(){pm.response.to.have.status(200);});//2.验证返回body内是否含有某个值pm.test("Bodymatchesstring",function(){pm.expect(pm.response.text()).to.include("string_you_want_to_search");});//3.验证某个返回值是否是100pm.test("Yourtestname",function(){varjsonData=pm.response.json
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions
我有一个使用SeleniumWebdriver和Nokogiri的Ruby应用程序。我想选择一个类,然后对于那个类对应的每个div,我想根据div的内容执行一个Action。例如,我正在解析以下页面:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies这是一个搜索结果页面,我正在寻找描述中包含“Adoption”一词的第一个结果。因此机器人应该寻找带有className:"result"的div,对于每个检查它的.descriptiondiv是否包含单词“adoption
我写了一个非常简单的rake任务来尝试找到这个问题的根源。namespace:foodotaskbar::environmentdoputs'RUNNING'endend当在控制台中执行rakefoo:bar时,输出为:RUNNINGRUNNING当我执行任何rake任务时会发生这种情况。有没有人遇到过这样的事情?编辑上面的rake任务就是写在那个.rake文件中的所有内容。这是当前正在使用的Rakefile。requireFile.expand_path('../config/application',__FILE__)OurApp::Application.load_tasks这里
如果names为nil,则以下中断。我怎样才能让这个map只有在它不是nil时才执行?self.topics=names.split(",").mapdo|n|Topic.where(name:n.strip).first_or_create!end 最佳答案 其他几个选项:选项1(在其上执行map时检查split的结果):names_list=names.try(:split,",")self.topics=names_list.mapdo|n|Topic.where(name:n.strip).first_or_create!e