基础2 win 32 Helloworld

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

源代码注释:

main.h

#ifndef __MAIN_H__
#define __MAIN_H__

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers

// Windows Header Files:
#include <windows.h>
#include <tchar.h>

// C RunTime Header Files
#include "CCStdC.h"

#endif    // __WINMAIN_H__

main.cpp

#include "main.h"
#include "AppDelegate.h"
#include "CCEGLView.h"

USING_NS_CC;

// uncomment below line, open debug console
// #define USE_WIN32_CONSOLE

int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

#ifdef USE_WIN32_CONSOLE
    AllocConsole();
    freopen("CONIN$", "r", stdin);
    freopen("CONOUT$", "w", stdout);
    freopen("CONOUT$", "w", stderr);
#endif

    // create the application instance
    AppDelegate app;
    CCEGLView* eglView = CCEGLView::sharedOpenGLView();	//显示的窗口
    eglView->setFrameSize(480, 320);	//窗口大小

    int ret = CCApplication::sharedApplication()->run();

#ifdef USE_WIN32_CONSOLE
    FreeConsole();
#endif

    return ret;
}

AppDelegate.h

#ifndef __APP_DELEGATE_H__
#define __APP_DELEGATE_H__

#include "cocos2d.h"

/**
@brief    The cocos2d Application.

The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/
class  AppDelegate : private cocos2d::CCApplication
{
public:
    AppDelegate();
    virtual ~AppDelegate();

    /**
    @brief    Implement CCDirector and CCScene init code here.
    @return true    Initialize success, app continue.
    @return false   Initialize failed, app terminate.
    */
    virtual bool applicationDidFinishLaunching();	//窗口启动完成(加载游戏,播放音乐)

    /**
    @brief  The function be called when the application enter background
    @param  the pointer of the application
    */
    virtual void applicationDidEnterBackground();	//窗口进入后台(音乐暂停,游戏暂停)

    /**
    @brief  The function be called when the application enter foreground
    @param  the pointer of the application
    */
    virtual void applicationWillEnterForeground();	//窗口恢复(音乐继续,游戏继续)
};

#endif  // __APP_DELEGATE_H__


AppDelegate.cpp

#include "cocos2d.h"
#include "CCEGLView.h"
#include "AppDelegate.h"
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"

using namespace CocosDenshion;

USING_NS_CC;

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
    SimpleAudioEngine::end();
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();	//初始化导演,他是引擎的老大
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());//绑定opengles窗口,可见,我们可以自定义openGLView

    // turn on display FPS
    pDirector->setDisplayStats(true);	//是否显示FPS ( 每秒绘制多少帧,最高60)

    // set FPS. the default value is 1.0/60 if you don't call this
	pDirector->setAnimationInterval(1.0 / 60);	//设置FPS 在cocos2d-x 启动后内部封装了FPS的逻辑,虽然helloWorld图片没变化,但其实一直在重绘

    // create a scene. it's an autorelease object
    CCScene *pScene = HelloWorld::scene();	// 创建一个场景

    // run
    pDirector->runWithScene(pScene);	// 显示这个场景到窗口,必然所有的绘制在场景中定义的
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->stopAnimation();

    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->startAnimation();

    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

#include "SimpleAudioEngine.h"

class HelloWorld : public cocos2d::CCLayer
{
public:
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    // there's no 'id' in cpp, so we recommand to return the exactly class pointer
    static cocos2d::CCScene* scene();
    
    // a selector callback
    void menuCloseCallback(CCObject* pSender);

    // implement the "static node()" method manually
    CREATE_FUNC(HelloWorld);
};

#endif  // __HELLOWORLD_SCENE_H__

HelloWorldScene.cpp

#include "HelloWorldScene.h"

using namespace cocos2d;

CCScene* HelloWorld::scene()
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::create();
        CC_BREAK_IF(! scene);	//判定是否成功,失败则退出

        // 'layer' is an autorelease object
        HelloWorld *layer = HelloWorld::create();
        CC_BREAK_IF(! layer);

        // add layer as a child to scene
        scene->addChild(layer);
    } while (0);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////

        CC_BREAK_IF(! CCLayer::init());

        //////////////////////////////////////////////////////////////////////////
        // add your codes below...
        //////////////////////////////////////////////////////////////////////////

        // 1. Add a menu item with "X" image, which is clicked to quit the program.

        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            "CloseNormal.png",		//缺省状态
            "CloseSelected.png",	//选中状态
            this,					//当前层
            menu_selector(HelloWorld::menuCloseCallback));//选中后的处理,消息回调方法
        CC_BREAK_IF(! pCloseItem);

        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));//(0,0)在左下角

        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);

        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);//第二参数是指放的顺序,值越小放的越底层

        // 2. Add a label shows "Hello World".

        // Create a label and initialize with string "Hello World".
        CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
        CC_BREAK_IF(! pLabel);

        // Get window size and place the label upper. 
        CCSize size = CCDirector::sharedDirector()->getWinSize();
        pLabel->setPosition(ccp(size.width / 2, size.height - 50));

        // Add the label to HelloWorld layer as a child layer.
        this->addChild(pLabel, 1);

        // 3. Add add a splash screen, show the cocos2d splash image.
        CCSprite* pSprite = CCSprite::create("HelloWorld.png");
        CC_BREAK_IF(! pSprite);

        // Place the sprite on the center of the screen
        pSprite->setPosition(ccp(size.width/2, size.height/2));

        // Add the sprite to HelloWorld layer as a child layer.
        this->addChild(pSprite, 0);

        bRet = true;
    } while (0);

    return bRet;
}

void HelloWorld::menuCloseCallback(CCObject* pSender)
{
    // "close" menu item clicked
    CCDirector::sharedDirector()->end();
}













Mediapipe框架学习之一——Win10安装Mediapipe环境 安装 Windows Subsystem for Linux (WSL),即Win10的子系统Linux 1.在 Microsoft Store 应用商店搜索并安装子系统 Windows Sysystem for Linux (Ubuntu) 注意:默认安装在C盘,不要改动!!! 注意:以下步骤全部在 WSL 中执行。 安装完成后,打开 WSL 按步骤初始化 ** WSL 的用户名、密码**。... 阅读详情

相关推荐

【1.Java基础】Java初识:从零搭建开发环境到写出第一个HelloWorld

本文是Java零基础入门的第一课,从Java的跨平台原理讲起,手把手带你完成JDK安装、环境变量配置,到用Android Studio写出第一个HelloWorld程序。平均阅读时长8分钟,适合没有任何编程经验的小白。

weixin_44081096的博客 732

stm32f765和h743说明文档

stm32f765系列和stm32h743系列说明文档,英文文档,需要的可以下载

dshow windowed mode

dshow里面的windowed mode 其实就是把graphedt弹出的框框以windowed mode的方式嵌入到mfc的对话框中

cocos2d-x应用窗口相关源码剖析5-其他细节

Cocos2d-x 的“HelloWorld” 细节分析   打开 HelloWorld 工程 , 里面有两个文件目录 Classes 和 win32 。 Classes 下有 HelloWorldScene.h/cpp ,AppDelegate.h/cpp. win32 下有 main.h/cpp 首先看一下 win32 目录下的 main.h, 其中定义了使用

bombing的专栏 953

COCOS2D-X源码分析之初始化游戏

#include "cocos2d.h" /**  CCEGLView  自适应模块业务 **/ #include "CCEGLView.h" #include "AppDelegate.h" #include "HelloWorldScene.h" #include "SimpleAudioEngine.h" /** @see 委托类 **/ using namespace

杰深的个人博客 837

Windows下让游戏窗口全屏

原文地址:http://www.eoeandroid.com/thread-250863-1-1.html 參考了一下NeHe 的教程, 在 cocos2d-x 2.0 上可以做點小手腳在 Windows 上全屏顯示! 主要修改兩個檔案: CCEGLView.h CCEGLView.cpp 它們在工程里的位置是 libcocos2d->platform->win32 先打開

爱在一毛钱 1548

cocos2dx进阶学习之CCEGLView

继承关系CCEGLView-> CCEGLViewProtocolCCEGLView是窗口,在不同平台上有不同的实现,而CCEGLViewProtocol是CCEGLView定义的接口,所以学习CCEGLView,主要是要学习CCEGLViewProtocol中定义的接口。类主要成员CCEGLView();构造函数,初始化所有成员变量。virtual void end();删除窗口,做窗...

weixin_30470643的博客 249

Python学习第一弹----环境配置及Pycharm安装和HelloWorld

本人电脑环境:win7 32位 一、python环境配置        (1)官网下载python 2.7.10【如果是win 8系统,貌似装3.5.0版本的会出错0x80240017】                  https://www.python.org/downloads/release/python-2710/ 二、IDE安装,使用Pycharm 201

ziwuchen的专栏 896

Java 基础2)Eclipse安装与HelloWorld运行

本篇文章将介绍Eclipse软件安装与语言学习入门程序helloworld程序的两种运行方式。(1)下载安装 Eclipse到官网(http://www.eclipse.org/downloads/packages/)下载 Eclipse IDE for Java EEDevelopers,一般选择最新版本。这里可以选择下载压缩包,解压后直接就可以使用。或是选择下载安装包,安装包点开后选择clip...

意志消沉的博客 750

Win10系统VS2019开发环境中(X86)Win32汇编(MASM32)环境配置和helloworld示例源码

微机原理课设进行的相关学习。

weixin_45679666的博客 1140

java编译 helloworld_HelloWorld.java,急!!!

HelloWorld.java程序代码:publicclassHelloWorld{publicstaticvoidmain(Stringargs[]){System.out.println("HelloWorld!");}}操作过程及提示:1.c:javacd:HelloWorld.java//成功生成HelloWorld.class文件2.c:java-classpa...

weixin_29603489的博客 865

win11 vs2010安装教程(超详细,附下载链接)

win11环境下安装Visual C++ 2010,帮助大家做一些常见的配置,以及第一次使用它来写人生的第一个HelloWord程序。环境准备1.win 10系统 2.迅雷或者百度云 3.解压工具安装的前准备首先查看电脑的位数 方法: 1.同时按Win键+R键,在打开的运行窗口中输入“dxdiag”,并确定。(Win键就是键盘上显示WINDOWS标志的按键) 可以看到系统是64位的

ifeng 17万+

win32Helloworld

更加应该说是一个普通Win32程序的Hello world。一直以来VC6.0常常是用来考试的,学校所教的程序都是一些DOS界面的控制台程序,即便是到了C++,当初憧憬满满的以为是从DOS界面升级到WIN界面,结果我惊讶地发现,不过是在C上的基础上加了一大堆什么类,然后继承、封装、多态,构造函数、析取函数给你讲一大堆,还有一大堆神人跟你扯int main()是比void main()正确,怒cao

编程记录,亲测有效 3409

Android环境搭建以及HelloWorld程序

最近忽然想玩一玩android,写几个小程序在自己的手机,于是开启我的android之旅。第一个挑战就是安装环境,在自己的电脑上折腾了三遍才算把HelloWorld给弄出来了,于是在公司的电脑上也装了一遍,写下以记录,希望给初学者一个参考。本机环境64位的Win7。         1.下载Java的JDK和Android的SDK(注意根据自己的机型选择32位和64位);         2.

2930

Win10环境下Android Studio中运行Flutter HelloWorld项目

博客总结了Flutter项目开发的基础环境搭建方法以及搭建过程中的常见问题

飞机火车巴雷特的博客 1271

Win11环境下IntelliJ IDEA下载安装及JDK配置 - JDK下载与安装第一个Java程序HelloWorld,JVM、JRE、JDK对比

本文主要用于首次安装IntelliJ IDEA、配置java环境及在正确的项目结构下书写第一个java程序

qq_55626883的博客 3995

[Win8]如何使用Visual Studio2012进行Windows8项目开发

随着Windows8普通版,专业版和企业版的普及,Windows8的应用开发也逐渐火热起来。 下面简单介绍一下如何使用Visual Studio2012进行Windows8项目的开发。 首先安装Windows8的操作系统,推荐安装32位的Win8,因为64位的容易出现不兼容的问题。 接下来就是Win8的激活。网上各种激活的方法很多,不过因为本人很懒,直接三块钱去淘宝买了一个激活序列号。 原

汪海的实验室 5513

crossApp初级-HelloWorld-3

HelloWorld工程由3个类组成,AppDelegate类是加载RootWindow实例对象的,FirstViewController 类是view 的控制器,用来交互 RootWindow 和其子view 。在win32 文件夹下是平台的入口函数,不同的平台有不用的main 类的实现,main 类中加载 AppDelegate 的对象,并调用run 方法。 一。RootWindow类 继

sylalak123的博客 434

java win7 32

Java在Win7 32位系统上的应用 在Windows 7 32位系统上,Java是一种广泛应用的编程语言,它具有跨平台、面向对象、高性能等特点,被广泛应用于企业级软件开发、移动应用开发等领域。本文将介绍Java在Win7 32位系统上的应用及相关示例代码。 Java环境搭建 在Win7 32位系统上搭建Java开发环境...

weixin_33914255的博客 230
上一篇: 基础1 概览
下一篇: 资源索引
格七
博客等级 码龄14年 0粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值