Skip to main content

News

Topic: Sphere Tip: Working with sprites (Read 4726 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Sphere Tip: Working with sprites
So I'm going to start things off with a series of tips for future Sphere Game Developers. Today I'll be talking about a neat trick for making maps quickly in your Sphere game.

Have you ever used Sphere's map editor and realized how slow or clunky it is to map out each item tile by tile? Well, there is a good remedy for that, at least when it comes to props such as trees, lamps, tables and other pieces of scenery or furniture. Use sprites.

We tend to think Sprites are NPC's. In Sphere at least, a person is regarded as an object that does some kind of action, whether it's on talk, touch, create or destroy. It may even have animations since they are tied to sprite sets. But what about static props? They don't interact with anything - and that's okay. Today we will be talking about the benefits of using sprites for mapping.

1. Dynamic sizes
If you change the look of the sprite you don't have to re-tile them. Now I know you don't have to worry about that since all external tilesets will affect the tiles on every map (if you repaint over the existing tiles). But if you make a tree taller, wider, or even smaller than it is, then it gets very messy very quickly on how you handle that. With a sprite, if you drastically change the size, you can see it everywhere immediately. No tiles or layers to mess with.

2. Easy placement
All you need to do is operate on the same layer the player sprite is on. Some trees and other tall objects may utilize several layers, e.g. the player layer, a top layer and maybe a ceiling layer. With a sprite, you only need to place it on the same layer as the player. If you want to move the sprite, you can just use the sprite mover tool and entire trees can be lifted and moved in a literal snap. Don't like one configuration of trees? Move them around a bit and see what works.

3. You get z-index shuffling
As a neat benefit, unlike tile layers, sprites reorganize. If the player sprite is behind a tree, it will shuffle in front of the player and vice-versa. This allows for neat depth effects, much better than what static ceiling layers give you.

4. You get advanced animation opportunities
That's right, since the tiles are now a sprite, you get frames and directions that you can animate. Throw down some code and the name of the person object you created and you can have your props react to the world around you. Light switches, chests, bushes that got caught on fire, you name it. If it's too much trouble to animate the tiles, animate a sprite instead!

5. You get analogue.js/persist.js support
For the experts here, in addition to advanced animation you can now store state with these sprites. A berry tree that grows berries only during certain times can be made easier moving the tiles into sprites. That is, if you use one of the advanced map scripting systems.

Now, hold on a sec! You don't want to convert everything into sprites. Keep your sprites only for NPC's and props. Terrain, cliffs, houses, and other larger and more static structures should remain as tiles. Animated water is hundreds of times better left as an animated tile rather than as an animated sprite. If it's going to take a lot of intricate tiles, stick to using tiles, but if the prop will be used throughout the map as a standalone object then use a sprite. Ask yourself if you want to move a tiled out tree vs. a tree sprite. You'll find the latter easier to manage.

Buildings could be sprites too, but due to the bounding boxes, it might be easier adding doors or layers with balconies the player can visit to tiles instead. I see buildings as cliffs. If it can't be climbed, but walked on, keep it as tiles. Lamp posts, signs and the like can be sprites. But objects that decorate cliffs - like windows and rock outcroppings - should remain as tiles.

By replacing props with sprites, not only do you get the advanced features listed above, but you will be creating and populating your maps in no time. If you are worried about performance, don't be.  Modern Sphere engines can handled hundreds of sprites on a map. In this era of 2D game design I'd take advantage of that whenever I can.
  • Last Edit: March 16, 2016, 06:05:16 pm by Radnen
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Sphere Tip: Working with sprites
Reply #1
Good idea, and nice write-up! Adding them to the wiki might be a good idea too. :)