- Panda3d 1.7 Game Developer's Cookbook
- Christoph Lang
- 436字
- 2021-04-09 21:21:44
Setting up the game structure
Through the course of this recipe you will learn the steps that are necessary to set up a very basic application structure to get your application going.
Getting ready
To follow the steps of this recipe you should have finished the first recipe in this chapter to have a properly configured development environment.
How to do it...
Follow these steps to create an empty project skeleton:
- Start NetBeans and click File | New Project… in the main menu.
- Select Python Project and click Next on the first screen of the New Project Wizard.
- On the New Python Project screen, set the Project Name and choose a Project Location. Also select Set as Main Project and Create Main File. Set the textbox to main.py, and check that the right Python Platform is active. Click Finish to proceed.
- Right-click the Project Name | Sources | Top Level item in the tree view in the Projects tab and select New | Empty Module.
- In the window that opens, set the File Name to Application and click Finish.
- Paste the following code into
Application.py
:from direct.showbase.ShowBase import ShowBase class Application(ShowBase): def __init__(self): ShowBase.__init__(self)
- The code that follows goes into
main.py
:from Application import Application if __name__ == "__main__": gameApp = Application() gameApp.run()
- Open your project directory in Windows Explorer and create folders called
models
andsounds
next to thesrc
folder. The folder structure should resemble the following screenshot: - Open the
Config.prc
file as described in the prior recipe and add the following lines:model-path $MAIN_DIR/../models model-path $MAIN_DIR/../sounds
- Hit F6 to run the application.
How it works...
First, we start by creating a new project in NetBeans. It generally is a very good idea to name the main file that will be launched by the Python runtime main.py
, so we are already set when we want to package our code and assets for redistribution later on.
The Application
class, derived from ShowBase
, is added as an abstraction of our game application. We must not forget to call the constructor of ShowBase
in the constructor of Application
or else there won't be a window opening when launching the program.
Because we do not want code files and assets to be scattered in a mess inside one single folder, we add folders dedicated to certain asset types. Depending on the type of project we intend to create, this setup may vary and we may wish to add additional folders. What's important about that is not to forget to add these extra folders to Panda3D's search paths too in Config.prc
, just like the models
and sounds
folders!
- Getting Started with Microsoft Application Virtualization 4.6
- 中文版Premiere影視編輯課堂實錄
- Hi!扁平化Photoshop扁平化用戶界面設計教程
- ERP沙盤模擬簡明教程
- 好的PPT會說話:如何打造完美幻燈片
- BIM與Unity 3D開發實例詳解
- 光影之書:Photoshop+Camera Raw攝影后期與創意合成
- Quickstart Apache Axis2
- PowerPoint 2013從新手到高手(超值版)
- Instant Testing with QUnit
- Photoshop CC摳圖+修圖+調色+合成+特效實戰視頻教程
- 機械CAD軟件應用入門指導書
- Photoshop+Illustrator+CorelDRAW一站式高效學習一本通
- NHibernate 3 Beginner's Guide
- Mobile Web Development