Bubble-Picker icon indicating copy to clipboard operation
Bubble-Picker copied to clipboard

dynamic add items

Open allenymt opened this issue 7 years ago • 2 comments

in pickerRender: fun addItem(pickerItem: PickerItem) { synchronized(this) { items.add(pickerItem) var newBody = Engine.buildBodiesWithOne(scaleX, scaleY) circles.add(Item(pickerItem, newBody)) textureIds = textureIds?.copyOf(circles.size * 2)

        vertices = vertices?.copyOf(circles.size * 8)
        textureVertices = textureVertices?.copyOf(circles.size * 8)

        initializeItem(circles.last(), circles.size - 1)
        verticesBuffer = vertices?.toFloatBuffer()
        uvBuffer = textureVertices?.toFloatBuffer()

    }
}

in Engine fun buildBodiesWithOne(scaleX: Float, scaleY: Float):CircleBody{ val density = interpolate(0.8f, 0.2f, radius / 100f)

    val x = if (Random().nextBoolean()) -startX else startX
    val y = if (Random().nextBoolean()) -0.5f / scaleY else 0.5f / scaleY
    var body= CircleBody(world, Vec2(x, y), bubbleRadius * scaleX, (bubbleRadius * scaleX) * 1.3f, density)
    bodies.add(body)
    return body
}

but the new item is always black, and no image or text

allenymt avatar Jan 08 '18 03:01 allenymt

when i press home ,then into app,it's ok.

allenymt avatar Jan 08 '18 03:01 allenymt

i found it ,beacuse of diff thread

todo like this:

override fun onDrawFrame(gl: GL10?) { if (hasNewItems){ var newBody = Engine.buildBodiesWithOne(scaleX, scaleY) circles.add(Item(items.last(), newBody)) textureIds = textureIds?.copyOf(circles.size * 2)

        vertices = vertices?.copyOf(circles.size * 8)
        textureVertices = textureVertices?.copyOf(circles.size * 8)

        initializeItem(circles.last(), circles.size - 1)
        verticesBuffer = vertices?.toFloatBuffer()
        uvBuffer = textureVertices?.toFloatBuffer()
        hasNewItems = false
    }
    calculateVertices()
    Engine.move()
    drawFrame()
}

allenymt avatar Jan 08 '18 04:01 allenymt