Hi,
this afternoon I started to work on a kind-of-simple module for BGE. It’s a 2D sprite module for BGE.
The module is really small and It’s firmly tied to BGE. That means a Sprite is an extension of a normal GameObject and you can program logic normally like you do with 3D.
It supports basic lighting, scaling and rotation of sprites.
Screenshots:
Lighting (it uses normal Blender lights, but it only works in Multitexture mode for some reason):
How to use:
- The sprite must use a GameObject with a mesh, a material and a texture. So you can use Object Color as well.
- You import the Batcher and Sprite modules, the Batcher must be initialized once and the Sprite must use controller.owner as constructor parameter to “mutate” the object.
- The object must have a basic mesh, but it cannot be hidden (otherwise the texture won’t bind). To overcome that, make a plane shaped like a / (so you can use Box collision) and flip the face orientation in such a way the camera cannot see it.
- The module folder “dd” must be alongside with your blend/exe in order to work
- You only need a simple init script to initialize the system.
from bge import logic
from dd.batcher import Batcher
from dd.sprite import Sprite
def init(cont):
# Create a new Batcher
logic.batcher = Batcher()
# Create a new Sprite by mutating cont.owner
logic.test = Sprite(cont.owner)
# Setup the sprite sheet and add animations.
# 4 and 9 are rows and columns respectively. The number of sprites vertically and horizontally.
# The parameters of add_animation is (name, speed, loop=True, frames=[])
# frames: The frames index array. You can find the indices by counting the sprites in the sprite sheet starting from bottom left.
# speed: The delay in seconds
logic.test.setup(4, 9).add_animation("default", 0.1, frames=[10, 11, 12, 13, 14, 15, 16, 17, 18])
# Submit this sprite to the Batcher. So it can be rendered and updated
logic.batcher.submit(logic.test)
# Other useful methods from Sprite
# set_animation: To set the animation currently being played (by name)
# animation_finished: To check whether an animation is finished or not (only if it's not looping)
You can run this by creating a simple logic-brick setup with a Python Module controller
The sprite sheet (numbers=sprite index):
This thread is intended for feedback and devlogs. I will be updating the source code with detailed tutorials/info. soon
Attachments
bge2d.zip (367 KB)