[Solved] Save/Load physics objects

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Snuux
Prole
Posts: 49
Joined: Sun Dec 15, 2013 10:43 am
Location: Russia, Moskow
Contact:

[Solved] Save/Load physics objects

Post by Snuux »

Hello!
My problem is:
For example I create polygon in editor (record every vertexes in array), and I want to save it. In next time I want to load polygon, that I save, in some different point.
I know how save array. But I don't , how recreate (with what attributes) polygon.

Please help! Thanks!)

I post attachments with my example programms (Simple Editor more easy to ).
Attachments
Simple Editor.love
(1.35 KiB) Downloaded 47 times
Editor.love
(1.61 KiB) Downloaded 42 times
Last edited by Snuux on Wed Jul 23, 2014 5:32 am, edited 1 time in total.
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)
User avatar
Snuux
Prole
Posts: 49
Joined: Sun Dec 15, 2013 10:43 am
Location: Russia, Moskow
Contact:

Re: Save/Load physics objects

Post by Snuux »

I Solve my problem. This is pseudo-code for saving.

Code: Select all

      local o = {} --our object with o.b - body, o.s - shape, o.f - fixture

      local s = {}
      s = {o.s:getPoints()} --Get all points!
      local cx, cy = o.b:getLocalCenter()
      for i=1, #s, 2 do --And from every point subtract local center
        s[i] = s[i] - cx
        s[i+1] = s[i+1] - cy
      end
      Slib.save(s)
And in next time, when we load objects with "s" coords, it's properly loads!

I attach example. Easy with mouse - create polygon. And in next time, load it with key "s"!
I use my library for saving, calling Slib. Feel free to use too.
Attachments
SavePolygon.love
"s" to load polygon
(3.71 KiB) Downloaded 46 times
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests