当前位置:  编程技术>移动开发
本页文章导读:
    ▪讯息推送系统设计        消息推送系统设计 Push Notification系统设计   一. 数据库表设计   1. 设备令牌表device_token   device_id: 设备标识,主键 device_type: 设备类型iOS或Android,必须字段 device_token: 设备令牌,设备类型为.........
    ▪ coco2d-x 2.0学习系列(1):SimpleGame(3)        coco2d-x 2.0学习系列(一):SimpleGame(3) cocos2d-x 2.0 SimpleGame知识点总结。 1.创建一个层的基本模板 virtual bool init(); static cocos2d::CCScene* scene(); CREATE_FUNC(MYSCENE);   2. CCDirector CCSprite CCArray .........
    ▪ coco2d-x 2.0学习系列(1):SimpleGame(2)       coco2d-x 2.0学习系列(一):SimpleGame(2) #ifndef __SIMPLE_GAME_H__ #define __SIMPLE_GAME_H__ #include "cocos2d.h" class SimpleGame:public cocos2d::CCLayerColor{ public: SimpleGame(); ~SimpleGame(); //初始化函数 virtual bool init(); s.........

[1]讯息推送系统设计
    来源: 互联网  发布时间: 2014-02-18
消息推送系统设计

Push Notification系统设计

 

一. 数据库表设计

 

1. 设备令牌表device_token

 

device_id: 设备标识,主键

device_type: 设备类型iOS或Android,必须字段

device_token: 设备令牌,设备类型为iOS时必须字段

user_id: 用户标识,可以为空

 

 

2. Android消息表notication

 

device_id: 设备标识

user_id: 用户标识

content: 消息体

 

 

二. 接口设计

 

  • 收集和更新设备令牌 post_device_token
  • 请求参数: 同数据库表device_token

    返回结果: 成功或失败标识

    业务逻辑: 

  • 以device_id为条件,没有纪录则新增,有纪录则更新
  • user_id刚开始为空,用户登录后加入,用户登出后清空
  •  

  • Android拉取消息 get_notification
  • 请求参数: 

    user_id: 用户标识,未注册用户或者已登出用户为空

    device_id: 设备标识,必须参数

    返回结果: 未推送消息列表

    业务逻辑: 

  • 有消息时纪录到表Notification中
  • 拉取时根据user_id和device_id进行匹配,2个字段任1个匹配即可。注意:user_id相同时要排除空user_id
  • 客户端拉取后立即清除
  •  

     

    三. 推送消息

     

  • iOS根据deviceToken直接发送;Android将消息纪录在Notification表中,等待拉取。
  • 用户相关的消息,根据user_id为过滤条件,为用户发送消息。

  •     
    [2] coco2d-x 2.0学习系列(1):SimpleGame(3)
        来源: 互联网  发布时间: 2014-02-18
    coco2d-x 2.0学习系列(一):SimpleGame(3)

    cocos2d-x 2.0 SimpleGame知识点总结。

    1.创建一个层的基本模板

    	virtual bool init(); 
             static cocos2d::CCScene* scene();
            CREATE_FUNC(MYSCENE);

      2.

    CCDirector CCSprite CCArray CCNode CCPoint CCMenu
    以及Action callfuncN_selector schedule CCMoveTo

      3.坐标系统

      4.碰撞问题

       总个游戏代码不多,但是包括场景的创建 场景的切换  精灵的创建 精灵的移动

      精灵的碰撞 精灵的销毁 音乐的播放等等。。


        
    [3] coco2d-x 2.0学习系列(1):SimpleGame(2)
        来源: 互联网  发布时间: 2014-02-18
    coco2d-x 2.0学习系列(一):SimpleGame(2)
    #ifndef __SIMPLE_GAME_H__
    #define __SIMPLE_GAME_H__
    #include "cocos2d.h"
    class SimpleGame:public cocos2d::CCLayerColor{
    
    public:
    	SimpleGame();
    	~SimpleGame();
    	//初始化函数
    	virtual bool init();  
    
    	static cocos2d::CCScene* scene();
    
    	// 菜单响应函数
    	virtual void menuCloseCallback(cocos2d::CCObject* pSender);
    	CREATE_FUNC(SimpleGame);
    	//精灵移动结束回调函数
    	void spriteMoveFinished(cocos2d::CCNode* sender);
    	//定时添加精灵回调函数
    	void gameLogic(float dt);
    	//碰撞检测
    	void updateGame(float dt);
    
    	void registerWithTouchDispatcher();
    	//触摸事件
    	void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
    
    
    protected:
    	cocos2d::CCArray *_targets;//敌人精灵集合
    	cocos2d::CCArray *_projectiles;//子弹精灵集合
    	int _projectilesDestroyed;//
    
    	void addTarget();//添加敌人精灵
    };
    
    #endif

     

    #include "SimpleGameScene.h"
    #include "GameOverScene.h"
    #include "SimpleAudioEngine.h"
    using namespace cocos2d;
    SimpleGame::SimpleGame():
        _targets(NULL)
    	,_projectiles(NULL)
    	,_projectilesDestroyed(0){}
    SimpleGame::~SimpleGame(){
    	if(_targets){
    		_targets->release();
    		_targets=NULL;
    	}
    	if(_projectiles){
    		_projectiles->release();
    		_projectiles=NULL;
    	}
    }
    //创建场景并且添加层
    CCScene* SimpleGame::scene(){
    	CCScene * scene = NULL;
    	do 
    	{
    		scene = CCScene::create();
    		CC_BREAK_IF(! scene);
    		SimpleGame *layer = SimpleGame::create();
    		CC_BREAK_IF(! layer);
    		scene->addChild(layer);
    	} while (0);
    	return scene;
    }
    //初始化
    bool SimpleGame::init(){
    
    	bool bRet = false;
    	do 
    	{
    		//初始化带颜色的层
    		CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(255,255,255,255) ) );
    
          //创建图片菜单item,并设置响应回调函数
    		CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
    			"CloseNormal.png",
    			"CloseSelected.png",
    			this,
    			menu_selector(SimpleGame::menuCloseCallback));
    		CC_BREAK_IF(! pCloseItem);
    
    		// OpenGL view size
    		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    		// visible origin of the OpenGL view in points
    		CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    		//设置pCloseItem位置
    		//#define ccp(__X__,__Y__) cocos2d::CCPointMake((float)(__X__), (float)(__Y__))
    		//宏ccp 返回point
           
    		/************************************************************************/
    		/*这个地方关联到coco2d-x坐标系         
    		基本的两个坐标系:屏幕坐标系和GL坐标系。
    		屏幕坐标系x轴朝右,y轴朝下。默认原点在左上角。
    		 O---------------->x
    		 |
    		 |
    		 |
    		 |
    		 y
    		GL坐标系x轴朝右,y轴朝上。默认原点在左下角。
    		 opengl
    		 y|
    		 |
    		 |
    		 |                   
    		 |                  
    		 O-------------------->x
    		 setPosition设置的是GL坐标
    		 setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
    		 origin.y + pCloseItem->getContentSize().height/2));
    		 这句实际上是把关闭按钮设置到到屏幕的右下角
    		 y
    		 |
    		 |
    		 |
    		 |                      ____
    		 |                     |__*_|    
    origin(x,y)---------------------------->x
    
    		*/
    
    		/************************************************************************/
    		pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
    			origin.y + pCloseItem->getContentSize().height/2));
    
    		CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    		pMenu->setPosition(CCPointZero);//这里必须设置才能显示菜单
    		CC_BREAK_IF(! pMenu);
    
    		//菜单添加到层
    		this->addChild(pMenu, 1);
            //创建英雄精灵       
    		CCSprite *player = CCSprite::create("Player.png", CCRectMake(0, 0, 27, 40) );
    		//创建精灵
    		player->setPosition( ccp(origin.x + player->getContentSize().width/2,
    			origin.y + visibleSize.height/2) );
    		this->addChild(player);
    		//定时增加敌人精灵,每一秒新增一个
    		this->schedule( schedule_selector(SimpleGame::gameLogic), 1.0 );
    		//设置可触摸
    		this->setTouchEnabled(true);
    
    		_targets = new CCArray;
    		_projectiles = new CCArray;
    		//检测碰撞
    		this->schedule( schedule_selector(SimpleGame::updateGame) );
    		//播放背景音乐
    		CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background-music-aac.wav", true);
    
    		bRet = true;
    	} while (0);
    
    	return bRet;
    }
    // 新增敌人精灵
    void SimpleGame::addTarget()
    {   
    	CCSprite *target = CCSprite::create("Target.png", CCRectMake(0,0,27,40) );
    
    	CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
    	float minY = target->getContentSize().height/2;
    	float maxY = winSize.height -  target->getContentSize().height/2;
    	int rangeY = (int)(maxY - minY);
    	int actualY = ( rand() % rangeY ) + (int)minY;
    
    	target->setPosition( 
    		ccp(winSize.width + (target->getContentSize().width/2), 
    		CCDirector::sharedDirector()->getVisibleOrigin().y + actualY) );
    	this->addChild(target);
    
    	// Determine speed of the target
    	int minDuration = (int)2.0;
    	int maxDuration = (int)4.0;
    	int rangeDuration = maxDuration - minDuration;
    	// srand( TimGetTicks() );
    	int actualDuration = ( rand() % rangeDuration ) + minDuration;
    
    	// 精灵移动action
    	CCFiniteTimeAction* actionMove = CCMoveTo::create( (float)actualDuration,
    		ccp(0 - target->getContentSize().width/2, actualY) );
    	CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, 
    		callfuncN_selector(SimpleGame::spriteMoveFinished));
    	target->runAction( CCSequence::create(actionMove, actionMoveDone, NULL) );
    
    	// 敌人精灵加入ccarray
    	target->setTag(1);
    	_targets->addObject(target);
    }
    
    void SimpleGame::spriteMoveFinished(CCNode *sender)
    {
    	CCSprite *sprite = (CCSprite *)sender;
    	this->removeChild(sprite, true);
    
    	if (sprite->getTag() == 1)  // target
    	{
    		_targets->removeObject(sprite);
    		//游戏失败切换场景
    		GameOverScene *gameOverScene = GameOverScene::create();
    		gameOverScene->getLayer()->getLabel()->setString("You Lose :[");
    		CCDirector::sharedDirector()->replaceScene(gameOverScene);
    
    	}
    	else if (sprite->getTag() == 2) // projectile
    	{
    		_projectiles->removeObject(sprite);
    	}
    }
    
    void SimpleGame::gameLogic(float dt)
    {
    	this->addTarget();//添加敌人精灵
    }
    
    void SimpleGame::menuCloseCallback(CCObject* pSender)
    {
    	// 响应menu时间
    	CCDirector::sharedDirector()->end();
    }
    // 触摸屏幕 添加子弹
    void SimpleGame::ccTouchesEnded(CCSet* touches, CCEvent* event)
    {
    	// Choose one of the touches to work with
    	CCTouch* touch = (CCTouch*)( touches->anyObject() );
    	CCPoint location = touch->getLocation();
    	//触摸按下的坐标
    	CCLog("++++++++after  x:%f, y:%f", location.x, location.y);
    
    	
    	CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
    	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    	CCSprite *projectile = CCSprite::create("Projectile.png", CCRectMake(0, 0, 20, 20));
    	projectile->setPosition( ccp(origin.x+20, origin.y+winSize.height/2) );
    
    	// Determinie offset of location to projectile
    	float offX = location.x - projectile->getPosition().x;
    	float offY = location.y - projectile->getPosition().y;
    
    	// Bail out if we are shooting down or backwards
    	if (offX <= 0) return;
    
    	// Ok to add now - we've double checked position
    	this->addChild(projectile);
    
    	// Determine where we wish to shoot the projectile to
    	float realX = origin.x+winSize.width + (projectile->getContentSize().width/2);
    	float ratio = offY / offX;
    	float realY = (realX * ratio) + projectile->getPosition().y;
    	CCPoint realDest = ccp(realX, realY);
    
    	// Determine the length of how far we're shooting
    	float offRealX = realX - projectile->getPosition().x;
    	float offRealY = realY - projectile->getPosition().y;
    	float length = sqrtf((offRealX * offRealX) + (offRealY*offRealY));
    	float velocity = 480/1; // 480pixels/1sec
    	float realMoveDuration = length/velocity;
    
    	// 移动子弹action
    	projectile->runAction( CCSequence::create(
    		CCMoveTo::create(realMoveDuration, realDest),
    		CCCallFuncN::create(this, 
    		callfuncN_selector(SimpleGame::spriteMoveFinished)), 
    		NULL) );
    
    	// Add to projectiles array
    	projectile->setTag(2);
    	_projectiles->addObject(projectile);
    
    	CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pew-pew-lei.wav");
    }
    //碰撞检测
    void SimpleGame::updateGame(float dt)
    {
    	CCArray *projectilesToDelete = new CCArray;
    	CCObject* it = NULL;
    	CCObject* jt = NULL;
    
    	// for (it = _projectiles->begin(); it != _projectiles->end(); it++)
    	CCARRAY_FOREACH(_projectiles, it)//遍历ccarray
    	{
    		CCSprite *projectile = dynamic_cast<CCSprite*>(it);//动态转换类类型
    		//飞镖矩形区域
    		CCRect projectileRect = CCRectMake(
    			projectile->getPosition().x - (projectile->getContentSize().width/2),
    			projectile->getPosition().y - (projectile->getContentSize().height/2),
    			projectile->getContentSize().width,
    			projectile->getContentSize().height);
    
    		CCArray* targetsToDelete =new CCArray;
    
    		// for (jt = _targets->begin(); jt != _targets->end(); jt++)
    		CCARRAY_FOREACH(_targets, jt)
    		{
    			CCSprite *target = dynamic_cast<CCSprite*>(jt);
    			CCRect targetRect = CCRectMake(
    				target->getPosition().x - (target->getContentSize().width/2),
    				target->getPosition().y - (target->getContentSize().height/2),
    				target->getContentSize().width,
    				target->getContentSize().height);
    
    			// 碰撞检测,2个精灵区域相交,即为碰撞。
    			if (projectileRect.intersectsRect(targetRect))
    			{
    				targetsToDelete->addObject(target);
    			}
    		}
    
    		// for (jt = targetsToDelete->begin(); jt != targetsToDelete->end(); jt++)
    		CCARRAY_FOREACH(targetsToDelete, jt)
    		{
    			CCSprite *target = dynamic_cast<CCSprite*>(jt);
    			_targets->removeObject(target);
    			this->removeChild(target, true);
    
    			_projectilesDestroyed++;
    			if (_projectilesDestroyed >= 5)
    			{
    				GameOverScene *gameOverScene = GameOverScene::create();
    				gameOverScene->getLayer()->getLabel()->setString("You Win!");
    				CCDirector::sharedDirector()->replaceScene(gameOverScene);
    			}
    		}
    
    		if (targetsToDelete->count() > 0)
    		{
    			projectilesToDelete->addObject(projectile);
    		}
    		targetsToDelete->release();
    	}
    
    	// for (it = projectilesToDelete->begin(); it != projectilesToDelete->end(); it++)
    	CCARRAY_FOREACH(projectilesToDelete, it)
    	{
    		CCSprite* projectile = dynamic_cast<CCSprite*>(it);
    		_projectiles->removeObject(projectile);
    		this->removeChild(projectile, true);
    	}
    	projectilesToDelete->release();
    }
    
    void SimpleGame::registerWithTouchDispatcher()
    {
    	// CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,true);
    	CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);
    }
    

     


        
    最新技术文章:
    ▪Android开发之登录验证实例教程
    ▪Android开发之注册登录方法示例
    ▪Android获取手机SIM卡运营商信息的方法
    ▪Android实现将已发送的短信写入短信数据库的...
    ▪Android发送短信功能代码
    ▪Android根据电话号码获得联系人头像实例代码
    ▪Android中GPS定位的用法实例
    ▪Android实现退出时关闭所有Activity的方法
    ▪Android实现文件的分割和组装
    ▪Android录音应用实例教程
    ▪Android双击返回键退出程序的实现方法
    ▪Android实现侦听电池状态显示、电量及充电动...
    ▪Android获取当前已连接的wifi信号强度的方法
    ▪Android实现动态显示或隐藏密码输入框的内容
    ▪根据USER-AGENT判断手机类型并跳转到相应的app...
    ▪Android Touch事件分发过程详解
    ▪Android中实现为TextView添加多个可点击的文本
    ▪Android程序设计之AIDL实例详解
    ▪Android显式启动与隐式启动Activity的区别介绍
    ▪Android按钮单击事件的四种常用写法总结
    ▪Android消息处理机制Looper和Handler详解
    ▪Android实现Back功能代码片段总结
    ▪Android实用的代码片段 常用代码总结
    ▪Android实现弹出键盘的方法
    ▪Android中通过view方式获取当前Activity的屏幕截...
    ▪Android提高之自定义Menu(TabMenu)实现方法
    ▪Android提高之多方向抽屉实现方法
    ▪Android提高之MediaPlayer播放网络音频的实现方法...
    ▪Android提高之MediaPlayer播放网络视频的实现方法...
    ▪Android提高之手游转电视游戏的模拟操控
     


    站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3