在PC上运行的Cocos2d-x for XNA “Hello world”

编译好的DLL文件下载地址:http://download.csdn.net/detail/qy1213/4141611

1、新建项目

2、添加DLL引用

3、编写两个类AppDelegate.cs和HelloWorldScene.cs

public class AppDelegate : CCApplication
    {
        public AppDelegate(Game game, GraphicsDeviceManager graphics)
            : base(game, graphics)
        {
            CCApplication.sm_pSharedApplication = this;
        }

        public override bool initInstance()
        {
            return base.initInstance();
        }

        public override bool applicationDidFinishLaunching()
        {
            CCDirector pDirector = CCDirector.sharedDirector();
            pDirector.setOpenGLView();
            pDirector.DisplayFPS=true;
            pDirector.animationInterval = 1.0 / 60;
            CCScene pScene = HelloCocos2dScene.scene();
            pDirector.runWithScene(pScene);

            return true;
        }

        public override void applicationDidEnterBackground()
        {
            CCDirector.sharedDirector().pause();
        }

        public override void applicationWillEnterForeground()
        {
            CCDirector.sharedDirector().resume();
        }
    }


public class HelloCocos2dScene : CCLayer
    {
        public override bool init()
        {
            CCDirector.sharedDirector().deviceOrientation = ccDeviceOrientation.CCDeviceOrientationLandscapeLeft;
            if (!base.init())
            {
                return false;
            }

            this.m_bIsTouchEnabled = true;
	        CCMenuItemImage pCloseItem = CCMenuItemImage.itemFromNormalImage(
										        "CloseNormal",
										        "CloseSelected",
										        this,
										        new SEL_MenuHandler(menuCloseCallback) );
	        pCloseItem.position = new CCPoint(CCDirector.sharedDirector().getWinSize().width - 20, 20);
	        CCMenu pMenu = CCMenu.menuWithItems(pCloseItem);
	        pMenu.position = new CCPoint(0, 0);
	        this.addChild(pMenu, 1);
            CCLabelTTF pLabel = CCLabelTTF.labelWithString("Hello World", "Arial", 24);
	        CCSize size = CCDirector.sharedDirector().getWinSize();
	        pLabel.position = new CCPoint(size.width / 2, size.height - 50);
            this.addChild(pLabel, 1);
	        CCSprite pSprite = CCSprite.spriteWithFile("HelloWorld");
	        pSprite.position = new CCPoint(size.width/2, size.height/2);
	        this.addChild(pSprite, 0);
	
	        return true;
        }
        CCSprite pSprite;
        public static CCScene scene()
        {
            CCScene scene = CCScene.node();
            CCLayer layer = HelloCocos2dScene.node();
            scene.addChild(layer);
            return scene;
        }

        public static new CCLayer node()
        {
            HelloCocos2dScene ret = new HelloCocos2dScene();
            if (ret.init())
            {
                return ret;
            }
            else
            {
                ret = null;
            }

            return ret;
        }
        public virtual void menuCloseCallback(CCObject pSender)
        {
            CCDirector.sharedDirector().end();
            CCApplication.sharedApplication().Game.Exit();
        }

        public override void ccTouchesBegan(List<CCTouch> touches, CCEvent event_)
        {

        }
    }


 public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            this.graphics.IsFullScreen = false;

            TargetElapsedTime = TimeSpan.FromTicks(333333);
            InactiveSleepTime = TimeSpan.FromSeconds(1);

            CCApplication application = new AppDelegate(this, graphics);
            this.Components.Add(application);
        }


程序运行结果:

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值