`
wangshu3000
  • 浏览: 132575 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

PSP程序开发例子解析(一)HelloWorld

阅读更多

今天晚上把PSP的开发环境搭建了起来 并且看了看PSP的HelloWorld 下面是介绍
开发环境搭建及Helloworld分析
具体需要下载的东西及详细配置在:
http://www.itshaik.com/bbs/thread-2385-1-1.html
1.PSPSDK
最新SVN编译版本+MSYS+GCC完整打包
官方地址
http://www.pspsp.org/main/?page_id=8
下载链接
http://www.aeolusc.com/down/PSPSDK_MSYS_FULL.7z
2.JGE++
PSP上的2D硬件加速的开发引擎
官方地址
http://jge.khors.com/
下载链接
http://jge.khors.com/JGE_1_0.zip
下载完后修改PSPSDK下的msys.bat文件
@echo off
bin \sh --login -i'
set PATH=d:\pspsdk\msys\bin;d:\pspsdk\pspdev\bin;%PATH%;cmd
将JGE解压文件放入 PSPSDK\home\sys_username\下   [sys_username 当前系统用户名称]
到这里为止 初步的编辑环境已经配置好了
通过D:
CD D:\PSPSDK\home\zmo\JGE\Tools
newproject test1 test
来新建立一个工程 用VisualStudio2005打开
newprocjets test1 test 是一个批处理 参数1是项目名称 参数2是psp上的ICON的名称
icon.jpg 是应用程序在目录中的图标
编写完项目后运行PSPSDK下的msys.bat
然后依次输入以下的代码
cd JGE\Projects\helloworld
make 3xx
然后去项目目录可以找到EBOOT.3xx了
记得要附上res文件夹 res文件夹要和EBOOT.BPB文件在同一目录下 然后连整个工程放到PSP的game下
今天开始学习例子Tutorials中的工程

从HelloWorld开始
整个Solution解决方案包括2个Project工程 一个是JGE图形环境的工程,默认生成 不去管它
另一个是真正需要编码的工程 包括的目录有:Header Files、Misc、Resource Files、Source Files
目录用途顾名思义 从头文件开始 最简单的程序共3个文件GameApp.h、GameApp.cpp、GameLauncher.cpp
GameApp.h的内容如下

 

//------------------------------------------------------------------------------------- // // JGE++ is a hardware accelerated 2D game SDK for PSP/Windows. // // Licensed under the BSD license, see LICENSE in JGE root for details. // // Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com> // //------------------------------------------------------------------------------------- #ifndef _GAMEAPP_H_ #define _GAMEAPP_H_ #include <JApp.h> class JLBFont; /* 引用到的一些类请在这里申明 */ class GameApp: public JApp//继承自JApp 应该是所有PSP应用程序的父类 { /* private 私有成员申明在这里 */ private: JLBFont* mFont; /* public 共有信息申明在这里 */ public: GameApp();//程序主类的构造函数 virtual ~GameApp();//析构函数 virtual void Create();//App创建时的方法 virtual void Destroy();//销毁 virtual void Update();//主要案件控制似乎在这个方法里 virtual void Render();//绘制图片 virtual void Pause();//点击Home按钮 跳出程序Pause virtual void Resume();//回来 }; #endif GameApp.cpp实现类 //------------------------------------------------------------------------------------- // // JGE++ is a hardware accelerated 2D game SDK for PSP/Windows. // // Licensed under the BSD license, see LICENSE in JGE root for details. // // Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com> // //------------------------------------------------------------------------------------- #include <stdio.h> #include <JGE.h> #include <JRenderer.h> #include <JLBFont.h> #include "GameApp.h" //------------------------------------------------------------------------------------- // Constructor. Variables can be initialized here. // 构造器.变量可以在这里被初始化 //------------------------------------------------------------------------------------- GameApp::GameApp() { mFont = NULL; } //------------------------------------------------------------------------------------- // Destructor. // 析构函数 //------------------------------------------------------------------------------------- GameApp::~GameApp() { } //------------------------------------------------------------------------------------- // This is the init callback function. You should load and create your in-game // resources here. // 这个是初始化函数的回调函数.你应在在这里加载并创建游戏中的资源 //------------------------------------------------------------------------------------- void GameApp::Create() { mFont = new JLBFont("f3", 16, true); } //------------------------------------------------------------------------------------- // This is the clean up callback function. You should delete all your in-game // resources, for example texture and quads, here. // 这是清理函数的回调函数.你应该在这里删除你游戏的所有资源 //------------------------------------------------------------------------------------- void GameApp::Destroy() { if (mFont) delete mFont; } //------------------------------------------------------------------------------------- // This is the update callback function and is called at each update frame // before rendering. You should update the game logic here. // 这是更新的回调函数.在描绘之前 你应该调用每个更新函数 //------------------------------------------------------------------------------------- void GameApp::Update() { JGE* engine = JGE::GetInstance(); // do a screen shot when the TRIANGLE button is pressed // 当按下△的时候 截图 if (engine->GetButtonClick(PSP_CTRL_TRIANGLE)) { char s[80]; // save screen shot to root of Memory Stick // 将截图保存到记忆棒 sprintf(s, "ms0:/screenshot.png"); JRenderer::GetInstance()->ScreenShot(s); } // exit when the CROSS button is pressed // 当按下○的时候退出 if (engine->GetButtonClick(PSP_CTRL_CROSS)) { engine->End(); return; } float dt = engine->GetDelta(); // Get time elapsed since last update. //=================================================================== // Your updating code here... // 在这里键入你的更新代码... //=================================================================== } //------------------------------------------------------------------------------------- // All rendering operations should be done in Render() only. // //------------------------------------------------------------------------------------- void GameApp::Render() { // get JRenderer instance // 获取 JRenderer实例 JRenderer* renderer = JRenderer::GetInstance(); // clear screen to black //将屏幕清屏为黑色 renderer->ClearScreen(ARGB(0,0,0,0)); mFont->SetColor(ARGB(255,255,255,255)); mFont->DrawString("Hello World!", 240.0f, 130.0f, JGETEXT_CENTER); //=================================================================== // Your rendering code here... //所有的主要代码应该放在这里 //================================================================== } //------------------------------------------------------------------------------------- // This function is called when the system wants to pause the game. You can set a flag // here to stop the update loop and audio playback. // 当系统想要暂停游戏的时候会调用这个函数.你可以在这里设置一个标志来暂停更新循环和声音的回放 //------------------------------------------------------------------------------------- void GameApp::Pause() { } //------------------------------------------------------------------------------------- // This function is called when the game returns from the pause state. // 这个函数会在系统从暂停中恢复过来的时候被调用 //------------------------------------------------------------------------------------- void GameApp::Resume() { } 最后的GameLauncher.cpp //------------------------------------------------------------------------------------- // // JGE++ is a hardware accelerated 2D game SDK for PSP/Windows. // // Licensed under the BSD license, see LICENSE in JGE root for details. // // Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com> // //------------------------------------------------------------------------------------- #include <JGameLauncher.h> #include "GameApp.h" //------------------------------------------------------------------------------------- JApp* JGameLauncher::GetGameApp() { return new GameApp();//负责初始化GameApp类 }; //------------------------------------------------------------------------------------- char *JGameLauncher::GetName() { /* 这里的名字 将会在XMB下显示 即是ICO的名字 */ return "template_desc"; } //------------------------------------------------------------------------------------- u32 JGameLauncher::GetInitFlags() { return JINIT_FLAG_NORMAL; } 
 

 


 Hello World 负责在图形界面输出HelloWorld字符串 应用F3字体 字体文件需要单独为每一个应用提供 包含一个.dat文件和一个.png文件

 

实现了按三角截屏,按叉退出的功能 通过调用JGE的End();

 

 

HelloWorld非常简单 明天看如何在屏幕上绘制图片 恩一共12个例子慢慢看 做一个双人队战的俄罗斯方块 然后各种优化

分享到:
评论
1 楼 白浪滔天 2008-07-19  
写的不错!加油噢

相关推荐

Global site tag (gtag.js) - Google Analytics