How to access resources from the engine?

32 views
Skip to first unread message

Tom

unread,
Oct 1, 2018, 8:43:34 AM10/1/18
to excaliburjs
Hi all,

I am working from the Webpack-ExcaliburJS example and I'm trying to access my resources from the player.ts file but this doesn't seem possible? Engine._loader is inaccessible from player.ts and I don't see any methods to GET it. Am I doing this wrong or should a GETTER be available in the Engine?

Kind regards,
Tom

Erik Onarheim

unread,
Oct 1, 2018, 11:25:00 PM10/1/18
to excaliburjs
Hi Tom,

You should be able to access resources by importing the resources directly where you need them. 

A common pattern that we've been using is to create a "resources.ts" file that contains all of the sounds and images for a game.

I have a work-in-progress sample upgrade that is a good example of a well structured excalibur game https://github.com/excaliburjs/sample-shootemup/tree/upgrade-excalibur

It has a non-trivial example of an excalibur game using webpack w/ resources.

Let me know if you have any questions,
Erik

Erik Onarheim

unread,
Oct 1, 2018, 11:29:03 PM10/1/18
to excaliburjs
Also we'd be very interested in any feedback you have while using excalibur.

It's good to have fresh eyes.

Thanks for checking it out!

Tom

unread,
Oct 2, 2018, 5:06:19 AM10/2/18
to excaliburjs
Hey,

Thanks for answering, very interesting! I was using the Webpack demo and saw that there the resources file was just the object of the files but he would load the resources in at index.ts

I forgot that require is a sort of "singleton"/cache thingy and thought that every require would reload all assets.

So the components will stay in memory?

Kind regards,
Tom



Op dinsdag 2 oktober 2018 05:25:00 UTC+2 schreef Erik Onarheim:

Erik Onarheim

unread,
Oct 2, 2018, 8:29:43 AM10/2/18
to excaliburjs
Hi Tom,

Correct, once resources have been loaded their data will stay in memory for the duration of the browser session by default. They can be reused by multiple Actors as needed.

Excalibur currently loads all assets provided to the loader before the first update of the game (big loading bar at the beginning). We have an issue in our backlog to do incremental or background loading as well https://github.com/excaliburjs/Excalibur/issues/960.

Cheers,
Erik

Kamran Ayub

unread,
Oct 2, 2018, 12:40:32 PM10/2/18
to Erik Onarheim, excaliburjs
Yeah what's neat too is with webpack you could do dynamic import code splitting to achieve that. Loader will queue up resources when you call game.loader.add (sorry, recalling from memory may not he exact) so you could call it when a scene starts.

--
You received this message because you are subscribed to the Google Groups "excaliburjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to excaliburjs...@googlegroups.com.
To post to this group, send email to excal...@googlegroups.com.
Visit this group at https://groups.google.com/group/excaliburjs.
To view this discussion on the web visit https://groups.google.com/d/msgid/excaliburjs/78bc7046-8d09-4524-bf65-e3bf535280bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom

unread,
Oct 3, 2018, 2:26:04 AM10/3/18
to excaliburjs
Webpack dymanic code splitting I wouldn't advice it for starters but if people want to try it out ;-)

Op dinsdag 2 oktober 2018 18:40:32 UTC+2 schreef Kamran Ayub:

Kamran Ayub

unread,
Oct 3, 2018, 8:35:53 AM10/3/18
to Tom, excaliburjs
With webpack v4 it's a lot easier/automatic but yes, webpack isn't for the feint of heart but is a good option for a production game. I'd like to enhance the webpack sample with v4 code splitting since we haven't tried it.

Also I'd like to try Parcel and make a template with it as well. We've done Rollup in the past and that also works nicely.

-Kamran

Reply all
Reply to author
Forward
0 new messages