from pythagoras.f.Path to playn.core.Path

5 views
Skip to first unread message

Andres Q

unread,
Mar 13, 2018, 9:28:49 AM3/13/18
to pl...@googlegroups.com
Hello,

As the subject suggests, I need to store in an object a Path (lines,
beziers and quads) so that later on I can draw that Path during the
game.

The problem is that in order to have a playn.core.Path I need an
instance of Canvas, which I don't have when I'm creating that object
(it's in startup phase, reading data from files) so I thought of using
pythagoras.f.Path to describe the path and storing it on the object,
and then when it's drawing time, transform pythagoras.f.Path to
playn.core.Path, since at that moment I will have an instance of
Canvas.

I wasn't able to find a simple way of transforming or populating a
playn.core.Path from it's pythagoras relative, is there an API for
this? Or maybe I'm approaching this the wrong way and there is a much
better way to solve this?

Thanks

Andrés

Michael Bayne

unread,
Mar 13, 2018, 12:36:37 PM3/13/18
to pl...@googlegroups.com
The Pythagoras Path class could fairly easily be used to create a PlayN Path, so that's not an unreasonable way to store "platform independent" paths in memory until you need to instantiate them into real PlayN paths.

That said, the only reason Path is created by Canvas is because each platform Path implementation needs OS-specific internal data structures, so it has to be created via *some* factory method, you can't just "new Path()" a PlayN path. But they could be created by Graphics instead of Canvas. I put Path creation in Canvas because most of the time you actually do have a Canvas and you want to create a Path and render it to that canvas, and you might not have a Graphics reference handy, so it's easier to get it from Canvas. But I should probably add it to Graphics as well, to underscore that there's no special relationship between a particular Canvas and a particular Path.

So that's a long winded way of saying, you could also just create a "dummy" Canvas and use that to create PlayN Path instances when unserializing your data and just keep those around directly.

--

---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Andres Q

unread,
Mar 13, 2018, 5:06:11 PM3/13/18
to pl...@googlegroups.com
Thanks, Michael!
Reply all
Reply to author
Forward
0 new messages