Level Data Question(s)

Hi there. I’m using v2.x of Cocos Creator. I was wondering about how to save level data (layout, x and y positions, etc.) without using tilemap like in this post. For the nodes whose layout I’d be saving, I’d also need to attach components to them. Initially, I created a new scene for every level but that seems very inefficient. I’m not quite sure how to read text files on startup and while threaded, which was recommended in the thread I linked. Also, what is the best way to write out each node and its details to a file as slackmoehrle said? Code examples would be appreciated.

You can use cc.resources.load to load the text:
https://docs.cocos.com/creator/2.4/manual/en/asset-workflow/text.html

You can use ‘jsb.fileUtils.writeStringToFile’ to write to a file.

I was wondering if writing out each node type’s details to a file manually beforehand and using module.exports so a level building script (containing the level data stored in a vector) can access the nodes is the best option. Like in @slackmoehrle’s example, each letter or number would represent a different node type.

This can save space and is a good choice.

I’m still unsure of how to include node position data (x,y) with this approach though, since each node’s position in the scene will be different, even if they are the same node type.

Do you mean you don’t know how to save the position of the node?

Yes, taking @slackmoehrle’s example, I’m not sure how to incorporate the node positions into the level layout.

I think you can refer to the design of @slackmoehrle and add P in front of the position.

Ok, thanks for the help! I appreciate it a lot.

hello i am working on game with similar desiign and ive implement an array with positions in json

"nodesInLevel": [ 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 0, 3, 4, 3, 4, 0, 1, 2, 2, 0, 0, 1, 2, 3, 0, 0, 0, 1, 2, 4 ],

  "positions":  [
    [0, 8], [7, 8], [0, 8], 
    [7, 8], [134, 80], [7, 8], 
    [20, 12], [7, 8], [0, 8], 
    [7, 8], [200, 80], [7, 8],
    [48, 79], [7, 8], [0, 8], 
    [0, 8], [443, 300], [0, 8], 
    [7, 8], [333, 222], [7, 8], 
    [60, 8], [7, 8], [0, 8], 
    [72, 56], [80, -85], [7, 8],
    [0, 8], [7, 8], [0, 8]
  ],`

is there better way to code this. where position is with nodesInLevel.?