keysabyl Posted June 17, 2019 Share Posted June 17, 2019 For a game I would like to load a text file (ex. fruit.txt) with some words in an array in Phaser 3. How can I do this? example of fruit.txt: apple banana strawberry lemon peach pear ... array: fruit[0] = apple fruit[1] = banana fruit[2] = strawberry fruit[3] = lemon fruit[4] = peach ... Quote Link to comment Share on other sites More sharing options...
keysabyl Posted June 18, 2019 Author Share Posted June 18, 2019 I found the solution myself: public preload{ this.load.text('fruit', 'assets/text/fruit.txt'); } public create{ this.loadFruit(); } private loadFruit(){ let cache = this.cache.text; let myFruit = cache.get('fruit'); this.arrayFruit = myFruit.split('\n');}; console.log(this.arrayFruit[3]); // >>> lemon } Phaser911 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.