Magnetic icon indicating copy to clipboard operation
Magnetic copied to clipboard

Only 1/2 of the bubbles are presented

Open jesster2k10 opened this issue 4 years ago • 7 comments

There is an issue in the current version of the library to which only half of the specified nodes are shown. This issue is related to #89, however, I thought it would be better to open a much more conclusive issue.

New Issue Checklist

Issue Description

The issue stems from the Magnetic view showing only half the number of nodes .i.e. showing 8 opposed to 15 nodes.

The cause of the issue is unknown, however, after some investigation, it seems to be that it has to do with the node.position set in the addChild function.

When I run print(node.position) I get the following in the console:

(0.0, 0.0)
(-105.53099822998047, -85.56782531738281)
(110.28900146484375, -44.71046829223633)
(-124.88300323486328, -49.56586456298828)
(80.25800323486328, -63.09857940673828)
(-150.05499267578125, 25.044469833374023)
(113.4219970703125, -64.8022232055664)
(-101.36699676513672, 93.44188690185547)
(137.75799560546875, -63.273929595947266)
(-143.57000732421875, -19.013620376586914)
(85.4530029296875, -7.014369964599609)
(-110.39099884033203, -63.73573303222656)
(137.75799560546875, -54.6263313293457)
(-118.06199645996094, 85.56877899169922)
(123.26599884033203, 119.49418640136719)
(-115.60199737548828, -95.26038360595703)

and only 8 elements are shown on the screen like so:

Simulator Screen Shot - iPhone 11 - 2020-04-04 at 20 14 44

however, when using the absolute position on both the x and y axis, so the node.position = CGPoint(x: abs(x), y: abs(y)),

and extra two elements are shown:

Simulator Screen Shot - iPhone 11 - 2020-04-04 at 20 16 12

Despite that, when showing the nodes count, 47 nodes are drawn onto the screen, more than are visible:

Simulator Screen Shot - iPhone 11 - 2020-04-04 at 20 18 20

So, my hypothesis is that the issue with only half of the items being shown stems with the positions they are assigned.

In particular, these lines in Magnetic.swift

override open func addChild(_ node: SKNode) {
        var x = -node.frame.width // left
        if children.count % 2 == 0 {
            x = frame.width + node.frame.width // right
        }
        let y = CGFloat.random(node.frame.height, frame.height - node.frame.height)
        node.position = CGPoint(x: abs(x), y: abs(y))
        print(node.position)
        super.addChild(node)
    }

Environment

  • iOS Version: iOS 13.3
  • Device(s): iPhone 11

It's worth nothing that this code is running in a react-native wrapper, from a library that I created around this https://github.com/jesster2k10/react-native-bubble-select

jesster2k10 avatar Apr 04 '20 19:04 jesster2k10

As I suspected, setting the node.position.y to 0 causes all of the nodes to appear like so:

Simulator Screen Shot - iPhone 11 - 2020-04-04 at 20 23 50

So my idea now, is that when the y-position is set randomly, there is a certain boundary, possibly the physics body, stopping the nodes from moving into the centre screen

jesster2k10 avatar Apr 04 '20 19:04 jesster2k10

Any progress on this?

nurlan-dzhavadov avatar Apr 14 '20 21:04 nurlan-dzhavadov

@dvlpd Are you working with the react-native or iOS library?

jesster2k10 avatar Apr 15 '20 08:04 jesster2k10

I work with iOS library, sir

nurlan-dzhavadov avatar Apr 15 '20 08:04 nurlan-dzhavadov

any updates?

nurlan-dzhavadov avatar May 12 '20 20:05 nurlan-dzhavadov

Hey @jesster2k10 any updates for the react-native lib?

josepedromonteiro avatar Jul 22 '20 01:07 josepedromonteiro

are you adding nodes inside viewDidLoad?

taier avatar Dec 12 '20 14:12 taier