+
Skip to content

SVG space player keep existing objects on play #226

@ogallagher

Description

@ogallagher

I have a page with an existing svg element that I loaded from a an asset file like icon.svg. Then I wanted to attach a pts Space to it to add additional interactive graphics, or to enable interaction on the existing objects within the svg. Is there a way for SVGSpace or SVGForm to be aware of these existing objects so they are persistent?

// svg: SVGSVGElement
const space = new SVGSpace(svg)
space.bindMouse()
space.add({
  /**
   * @param type Event type, simplification of raw `event.type`.
   * @param x Location x.
   * @param y Location y.
   * @param event Event.
   */
  action: function (type, x, y, event) {
    form.scope(this)
    form.fill('red')
     // simple example to draw red cursor at pointer location
    form.circle(Circle.fromCenter([x, y], 10))
  }
} as IPlayer)

// when this method is called, all existing objects in `svg` are deleted
space.play()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载