Spherical forums

User-Made => Libraries => Topic started by: Rhuan on November 05, 2017, 12:37:19 pm

Title: MapEngine for Sphere v2
Post by: Rhuan on November 05, 2017, 12:37:19 pm
This is still an alpha version I suppose but really needs some usage so I can know what else to do with it.

Feels good enough to share as a release of sorts now rather than just a project.


See the "Map Engine tutorial.md" file for a fairly brief getting started tutorial - it's a lot of files to put in your project but should hopefully be simple to use once in place.

Any questions let me know.

Note: this requires miniSphere version 5.0 (or later) it will not run with earlier versions and certainly won't run with Sphere 1.5.
Title: Re: MapEngine for Sphere v2
Post by: DaVince on November 10, 2017, 01:00:42 am
I think this thread could benefit from some visual benefits that the map engine offers! I'll start by showing the zooming capabilities of the map engine, as well as the flexible HUD/GUI system that is built around it.
Title: Re: MapEngine for Sphere v2
Post by: scojin on July 10, 2018, 03:18:40 pm
I'm trying to use the map engine, but I keep getting an error:

uncaught JavaScript exception

RangeError: Invalid read size '-929892776'
   at TileBuffer (@/src/MapEngine/PixelBuffer.mjs:171:9)
   at MEngine.prototype.setMap (@/src/MapEngine/MEngine.mjs:380:9)
   at Generator.prototype.next (native code)
   at MapEngine.prototype.start (@/src/MapEngine/map-engine.mjs:168:9)
   at Generator.prototype.next (native code)
   at Anonymous function (@/src/main.mjs:199:1)
   at module (@/src/main.mjs:2:1)

I followed the template for cellscript and the mainscript and made the file path adjustments where necessary.
I'm using .rmp maps. I tried making a new map, and I also tried making a map with only a single layer, but still get the error. My tile sizes are 16x16, but that isn't what comes back in the debugger. Is there something I'm missing? Probably something simple...   :-\
Thanks in advance!
Title: Re: MapEngine for Sphere v2
Post by: Rhuan on July 10, 2018, 04:45:54 pm
That's not an error I've seen, please could you post a sample project that produces it and I'll take a look?

My map engine should support any (positive) tile size and any number of layers.

At a guess - "-929892776" sounds like the wrong file is being read for the map - possibly the cellscript is wrong or you're trying to load the original .rmp file at runtime rather than the .mem file that the cell script will turn it into.
Title: Re: MapEngine for Sphere v2
Post by: scojin on July 10, 2018, 10:58:50 pm
That was absolutely it. I didn't have my map's file extension as .mem. I guess I overlooked the fact of having to change it. Same with my sprites, also; had to change them to .ses. I figured it was something simple.
Bleh. Thanks for the quick response!
Title: Re: MapEngine for Sphere v2
Post by: Fat Cerberus on July 10, 2018, 11:08:36 pm
Well, it's not just a matter of renaming the file, for the record - the file extension is just a hint to programs.  You actually need to convert the .rmp map to the .mem format, which is what the included Cellscript does.  Same deal with the spritesets.
Title: Re: MapEngine for Sphere v2
Post by: scojin on July 11, 2018, 07:18:17 pm
So, I got the MapEngine to work with the simple template method; I was even able to change walking speeds and utilize the zoom aspect. But when I use the code for the more 'dynamic' version, I'm running into a few problems. There are no errors called and the game loads up fines, but the map isn't drawn correctly and none of the input works.
I created a new project, copy-pasted the code, adjusted for custom map and sprite, and still got the same result. I'll post some pics and a link to the smaller project I made.

Spoiler (click to show/hide)
Spoiler (click to show/hide)
Title: Re: MapEngine for Sphere v2
Post by: Rhuan on July 11, 2018, 08:20:31 pm
I've temporarily deleted that larger example from the github repository I wrote some of that a while ago when I was still designing the map engine and I'm afraid I never updated it for some key changes so it doesn't behave correctly anymore. I'm really sorry about this failure.

I'd reccomend building upon the simpleExample instead for now - the map-engine.mjs interface it uses should be good enough for most things.

Edit: easier fixes than I thought:
1. Change the update function (line 92) so the parameters are this.camera.x, this.camera.y and this.camera.zoom (i.e. without the square brackets around the x and y)
2. add this.spriteSystem.takeInput(); anywhere in the start function

With these two changes it should work BUT I'm not going to put it back on GitHub for now as IMO it's not the best way to do things, the simpleExample (whilst it covers a few less features) is a better starting point at the moment.