将两个SKSpriteNode连接在一起 [英] Joining two SKSpriteNode together

查看:137
本文介绍了将两个SKSpriteNode连接在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨代码项目成员



我迫切需要一些帮助,请参阅下文。我无法找到解决方案!



iPhone 6演示应用

使用SpriteKit



我想做的是将两个SKSpriteNode连接在一起。



节点1平方100x100

节点2平方50x50



我希望两个节点在GameScene中是独立的,我希望能够拖放场景中的每个节点,但是如果我拖动节点2在节点1(左上角)并释放我的手指,节点2锚定到左上角的节点1。现在,当我移动节点2时,节点1随之移动。



如果我再次按下节点2,则锚定将被删除,并且2个节点将再次独立。 />


我希望节点1的每个角都能发生同样的事情。



我希望能够使用相同的功能将其他节点添加到场景中。因此每个Node都有自己的类。



我希望这是有道理的。



可以一个你们有关于如何实现这些代码或方向的帮助吗?



提前致谢!

Hi Code Project Members

I am in dire need of some help, please see below. I am having trouble finding a solution!

iPhone 6 Demo App
Using SpriteKit

What I would like to do is to attach two SKSpriteNodes together.

Node 1 square 100x100
Node 2 square 50x50

I would like the two nodes to be independent within the GameScene, I would like to be able to drag and drop each node within the scene, but if I drag node 2 over Node 1 (top left corner) and release my finger, Node 2 anchors to Node 1 in the top left corner. Now when I move Node 2, Node 1 moves with it.

If I press node 2 again, the anchoring is removed and the 2 Nodes are independent again.

I would like the same to happen for each corner of Node 1.

I would like to be able add additional Nodes to the scene with the same functionality. There fore each Node will have its own class.

I hope that makes sense.

can one of you guys help with sample code or direction on how this can be achieved?

Thanks in advance!

推荐答案

忘记添加,两个节点都需要受物理影响
Forgot to add, both Nodes need to be affected by Physics


这篇关于将两个SKSpriteNode连接在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆