Book Image

Panda3D 1.7 Game Developer's Cookbook

Book Image

Panda3D 1.7 Game Developer's Cookbook

Overview of this book

Table of Contents (20 chapters)
Panda3D 1.7 Game Developer's Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Rendering text to the screen


This simple recipe will show you how to quickly put some text on the screen. This might be useful for debug output, but also for presenting the current score or hit points to the player.

Getting ready

If you haven't done it yet, set up your project according to the steps presented in the recipe Setting up the game structure before you proceed. You can find this recipe in Chapter 1, Setting Up Panda3D and Configuring Development Tools.

How to do it...

Let's put some text on the screen:

  1. Open Application.py and add the following source code:

    from direct.showbase.ShowBase import ShowBase
    from direct.gui.OnscreenText import OnscreenText
    from panda3d.core import *
    
    class Application(ShowBase):
        def __init__(self):
            ShowBase.__init__(self)
            font = loader.loadFont("cmr12.egg")
            props = TextProperties()
            props.setTextColor(1, 1, 0, 0.5)
            tp = TextPropertiesManager.getGlobalPtr()
            tp.setProperties("yellow", props)
    
            OnscreenText...