Hello everyone, hope this is the right place to get some help but i am in a bit of a jam…
Lately, after playing around with blender, I’ve been getting into the knack of messing around with the Blender Game Engine and after spending time experimenting on the BGE I wanted to spend some of my free time trying to develop an actual video game.
In one of my experimental files, i am trying to recreate a heads up display inspired and based on the HUD from my favorite side scrolling shoot-em-up: GRADIUS. (note: GRADIUS III is my childhood favorite!)
This is what I am aiming for:
This image was made in an image/photo editor as a demonstration but the sprites in the image are real. I am attempting to load the sprites from ‘Speed’ to ‘?/Special’ icons.
This is the code below, using python to attempt to load the sprites saved as PNG:
import bge# import game engine modules
from bge import render
from bge import logic
# import stand alone modules
import bgl
def init():
"""init function - runs once"""
# create a HUD, use external png file
avatar_path = logic.expandPath('//materials/heads_up_display/avatar.png')
speed_path = logic.expandPath('//materials/heads_up_display/speed.png')
missle_path = logic.expandPath('//materials/heads_up_display/missle.png')
laser_path = logic.expandPath('//materials/heads_up_display/laser.png')
option_path = logic.expandPath('//materials/heads_up_display/option.png')
shield_path = logic.expandPath('//materials/heads_up_display/shield.png')
special_path = logic.expandPath('//materials/heads_up_display/special.png')
# store the png indice - to use later
avatar_source = texture.ImageFFmpeg(avatar_path)
speed_source = texture.ImageFFmpeg(speed_path)
missle_source = texture.ImageFFmpeg(missle_path)
laser_source = texture.ImageFFmpeg(laser_path)
option_source = texture.ImageFFmpeg(option_path)
shield_source = texture.ImageFFmpeg(shield_path)
special_source = texture.ImageFFmpeg(special_path)
# set the image rendering routine to run every frame
scene = logic.getCurrentScene()
scene.post_draw = [render]
def hud():
"""render on screen"""
width = render.getWindowWidth()
height = render.getWindowHeight()
# OpenGL setup
bgl.glMatrixMode(bgl.GL_PROJECTION)
bgl.glLoadIdentity()
bgl.gluOrtho2D(0, width, 0, height)
bgl.glMatrixMode(bgl.GL_MODELVIEW)
bgl.glLoadIdentity()
# rendering routine
special_source.position((width * 0.2), (height * 0.3))
special_source.draw
#the command at the end to test the rendering (But nothing comes up)
hud()
This code was from one of the examples of the Blender Python API used to load fonts but remodified to load images instead. I do have some knowledge of python (While I am still learning some more) but so far the code does not work and the only error i got is this:
“global name “special_source” is not defined.”
I was attempting to render out the ‘?/Special’ PNG but it didn’t work and I can already tell that there are more things within this code that is so wrong but I did gave it my best to try at least.
If anybody has a good knowledge of Python scripting in Blender please, let me know. Hopefully we can learn a little something within the python coding that will continue to improve the Blender Gaming Engine beyond its own limits.
(P.S. Hopefully this is the right place to post this and that this information was not too much… if not, then… WHOOPS.)