Spherical forums

Sphere Development => Sphere General => Topic started by: Miscreant on August 23, 2017, 11:10:46 pm

Title: Surfaces
Post by: Miscreant on August 23, 2017, 11:10:46 pm
Quote from: DaVince
you can create a little Sphere game that draws the whole map to a Surface object, and then save that Surface out to an image file.

Any good tutorials for using surfaces with sphere 1.5?
Title: Re: Surfaces
Post by: Rhuan on August 24, 2017, 02:02:41 am
Not seen a tutorial but they're easy enough, key functions for getting started with them:
1. image_object.createSurface() turns an existing image into a surface
2. Or you can use CreateSurface(width, height, color) to make a new rectangular surface filled with a colour
3.  surface_object.blitSurface(surface, x, y) draws one surface onto another, (the surface passed as a parameter is the one drawn, the one the function is called as a property of is the target)
4. surface_object.save(filename) saves the surface as an image file, you should specify a type by giving it an extension (I'd normally use ".png".

Now if you want to draw the map onto a surface I think you'll also need:
1. GetTile(x, y, layer) - should return the index of the tile at x, y, layer
2.GetTileSurface(tile_index) - should return a surface object for a given tile index
3. GetNumTiles() - should tell you how many tiles there are (should enable you to limit how many times you call GetTileSurface)
Title: Re: Surfaces
Post by: Miscreant on August 24, 2017, 02:20:03 am
That should help me get started with the surfaces. The Original overworld map for ZeC I made using Gimp has alot of erronious data to it. I thought maybe I'd try @DaVince 's suggestion to try to eliminate the errors. Now, I have a clear description of how to begin.
Title: Re: Surfaces
Post by: Miscreant on August 24, 2017, 03:36:11 am
So much more professional looking than what I originally created with Gimp. Much appreciated @Rhuan
Title: Re: Surfaces
Post by: Rhuan on August 24, 2017, 05:45:55 pm
So much more professional looking then what I originally created with Gimp. Much appreciated @Rhuan
Glad I could help.

One other note, if you wanted to show an in game mini-map you could use the code you've written and couple it with:
surface_object.rescale(w, h) to scale it down.

You can then do surface_object.createImage() to return a normal image ready for drawing with .blit().
Title: Re: Surfaces
Post by: Miscreant on August 24, 2017, 07:18:50 pm
That will be useful when I code the map function in dungeon levels.