Is it possible to import sprite in real-time, and save it inside playcanvas project ?
Can you clarify a bit?
Do you want to create a sprite at runtime and use it in the app for that session or forever as part of the project itself?
I need to implement a feature, that allows the user to import sprite, and position it on the screen
After he reopens the app again, it’s going to show last uploaded sprite until he set the new one from the import
That is fine, you can load an image at runtime and create sprite asset from that. There’s an example here you can adapt: [SOLVED] Create Sprite programmatically - #8 by yaustar
This part you will need to support as part of the app. I’m guessing you can use the browser’s localstorage Window.localStorage - Web APIs | MDN to store the image in some format and grab it again the next time the user runs the app.
If you need it to be tied to the user so that it works across computers, you will need to store it in some user account system that is in the cloud.
So i have to create a new server for this purpose
Do you have any advice on how can I transfer the image, via socket or?
It depends on your exact needs. If you only need to exist on that computer for that user, use localstorage should be enough.
Hey @Dava, to add on to what @yaustar said, IndexedDB might be a good choice. It’s especially designed, as per the MDN docs, “for client-side storage of significant amounts of structured data, including files/blobs”, so I think this will be ideal for your use case. Apart from the MDN guide I linked above, you could also look into the Google developers guide for greater clarity.
Hope this helps!
It’s for any user who has access to my app
I am already building a server for this, thank you for the help guys
But I am really wondering why there is no such a feature inside Playcanvas , it would be really helpful to store stuff in runtime and save it inside project on the server
We don’t provide backend services for builds and given the sheer number of possible services out there and possible stacks, it’s not really scalable for us to compete.
It’s the same reason why we don’t provide multiplayer support too.
We stay technology independent as much as possible and purely focus on the engine and editor services.
Any user that has access to the app for that session? PC? Or account? There are very different requirements based on how you are managing users and where you want the data to persist.
We have 1 user for the back office, who can change the sprite
and anyone who accesses to our app can see that sprite
So this is more CMS?
Depending on what this is, you can have a simple JSON config file or REST API endpoint that can give information about these sprites, including the URL and load/create the asset at runtime.
Or you can add the sprite to the Editor and just upload a new build?
I ended up building a CMS in Drupal for serving dynamic files and collecting analytics in my builds. If you take a reference based approach, you can just give your assets ids and then have the server spit out the corresponding file with just the ID. That way the users with permission can replace the files as they please and you’re not dependent on file names because the build is only asking for a reference id and the server finds the file for you.
Hope this is helpful.
I’ve used Drupal as well, as a CMS for serving content to PlayCanvas, and it worked beautifully. It can be a bit complex to setup but it’s powrful as a Rest provider.