#include "HelloWorldScene.h"
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
srand(time(NULL));
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
#if 0
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
#endif
// add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("bg_main.png");
// position the sprite on the center of the screen
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
// add bg_circul
pSprite_circle = CCSprite::create("bg_circle.png");
// pSprite_point->setScale(1.8f);
pSprite_circle->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(pSprite_circle, 0);
// add bg_point
CCSprite* pSprite_point = CCSprite::create("bg_point.png");
pSprite_point->cocos2d::CCNode::setAnchorPoint(ccp(0.5, 0.0));
// pSprite_point->setScale(1.8f);
pSprite_point->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y + 30));
this->addChild(pSprite_point, 1);
// add bg_center
CCSprite* pSprite_center = CCSprite::create("bg_center.png");
// pSprite_center->setScale(1.8f);
pSprite_center->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(pSprite_center, 1);
for (int i = 0; i < MAX_COUNT; i++) {
char bt_name[15] = {0};
sprintf(bt_name, "bt_%d.png", i + 1);
char selected_name[20] = {0};
sprintf(selected_name, "bt_selected_%d.png", i + 1);
CCSprite* pSprite_bt = CCSprite::create(bt_name);
CCSprite* pSprite_selected = CCSprite::create(selected_name);
CCMenuItemImage *pCloseItem = CCMenuItemImage::create();
// pCloseItem->setScale(1.8f);
pCloseItem->setTag(i);
pCloseItem->initWithNormalSprite(pSprite_bt, pSprite_selected, pSprite_bt, this, NULL);
pCloseItem->setAnchorPoint(ccp(0.5, 0.0));
pCloseItem->setPosition(ccp(pSprite_circle->getContentSize().width/2 + origin.x, pSprite_circle->getContentSize().height/2 + origin.y));
pCloseItem->setRotation(360 / MAX_COUNT * i);
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
pSprite_circle->addChild(pMenu, 0);
}
CCMenuItemImage *pButton = CCMenuItemImage::create();
pButton->initWithNormalImage("CloseNormal.png", "CloseSelected.png", "CloseNormal.png", this, menu_selector(HelloWorld::menuButtonCallback));
pButton->setPosition(ccp(visibleSize.width/2 + origin.x, 40));
m_menuStop = CCMenuItemFont::create("停止", this, menu_selector(HelloWorld::menuButtonCallbackStop));
m_menuStop->setPosition(ccp(visibleSize.width/2 + origin.x + 100, 40));
m_menuStop->setEnabled(false);
CCMenu* pMenu = CCMenu::create(pButton, m_menuStop, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 0);
return true;
}
void HelloWorld::menuButtonCallbackStop(CCObject* pSender)
{
m_menuStop->setEnabled(false);
pSprite_circle->stopAllActions();
pSprite_circle->setRotation(360* (3 + CCRANDOM_MINUS1_1()*0.5) /MAX_COUNT); //改变里面的数字 更改停的位置
CCActionInterval* actionTo_1 = CCRotateBy::create(1.5, 360 * 2);
CCActionInterval* actionTo_2 = CCRotateBy::create(0.5, 144);
CCActionInterval* actionTo_3 = CCRotateBy::create(0.65, 108);
CCActionInterval* actionTo_4 = CCRotateBy::create(0.85, 72);
CCActionInterval* actionTo_5 = CCRotateBy::create(1.0, 36);
pSprite_circle->runAction(CCSequence::create(actionTo_1,actionTo_2, actionTo_3, actionTo_4, actionTo_5,NULL));
}
void HelloWorld::menuButtonCallback(CCObject* pSender) {
m_menuStop->setEnabled(true);
static int old_pos = 0;
static bool need_rotation = false;
int pos = CCRANDOM_0_1() * MAX_COUNT;
CCLOG("pos is %d", pos);
if (!need_rotation) {
need_rotation = true;
CCLOG("old_pos id %d", old_pos);
CCActionInterval* actionTo_5 = CCRotateBy::create(1.0, 36);
CCActionInterval* actionTo_4 = CCRotateBy::create(0.85, 72);
CCActionInterval* actionTo_3 = CCRotateBy::create(0.65, 108);
CCActionInterval* actionTo_2 = CCRotateBy::create(0.5, 144);
CCActionInterval* actionTo_1 = CCRotateBy::create(2.5, 360 * 5);
pSprite_circle->runAction(CCSequence::create(actionTo_5, actionTo_4, actionTo_3, actionTo_2, actionTo_1,CCCallFunc::create(this, callfunc_selector(HelloWorld::menuButtonCallbackStop)),NULL));
pSprite_circle->runAction(CCRepeatForever::create(actionTo_1));
old_pos = pos;
need_rotation = false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
cocos2d-x游戏-转盘抽奖
共74个文件
png:62个
h:3个
cpp:3个
4星 · 超过85%的资源 需积分: 9 224 下载量 73 浏览量
2014-08-26
22:06:15
上传
评论 1
收藏 2.74MB ZIP 举报
温馨提示
cocos2d-x游戏-转盘抽奖,包含加速启动,降速停止,最重要的是根据后台想挺哪就停哪
资源推荐
资源详情
资源评论
收起资源包目录
lottery.zip (74个子文件)
lottery
proj.win32
main.h 267B
cocos2dx-lottery.vcxproj.user 645B
cocos2dx-lottery.sln 4KB
cocos2dx-lottery.vcxproj.filters 1KB
cocos2dx-lottery.vcxproj 11KB
main.cpp 600B
cocos2dx-lottery.suo 13KB
Resources
bt_selected_12.png 15KB
fonts
Marker Felt.ttf 25KB
bg_center.png 17KB
bg_main.png 235KB
bt_selected_8.png 16KB
bt_8.png 14KB
bt_selected_4.png 16KB
bt_8@2x.png 44KB
CloseSelected.png 5KB
bt_selected_6.png 16KB
bg_main@2x.png 213KB
bt_selected_10@2x.png 48KB
bt_10.png 14KB
bt_selected_7@2x.png 48KB
bt_9@2x.png 44KB
bt_selected_7.png 16KB
bt_6.png 14KB
bt_selected_11@2x.png 49KB
CloseNormal.png 6KB
bt_2@2x.png 43KB
blackArrow@2x.png 2KB
bt_selected_8@2x.png 50KB
bt_selected_3.png 16KB
bt_2.png 13KB
bg_circle@2x.png 448KB
bt_selected_11.png 16KB
bg_point.png 6KB
bt_1.png 14KB
bt_1@2x.png 41KB
bt_selected_3@2x.png 49KB
bt_selected_2@2x.png 47KB
bg_point@2x.png 12KB
bt_4@2x.png 44KB
bt_3@2x.png 44KB
bt_12@2x.png 45KB
bt_selected_4@2x.png 49KB
bt_selected_10.png 15KB
bt_6@2x.png 44KB
bt_selected_5.png 16KB
bt_selected_9@2x.png 48KB
bt_12.png 14KB
bt_7@2x.png 42KB
bt_selected_2.png 15KB
bg_circle.png 147KB
bt_9.png 14KB
bt_selected_12@2x.png 48KB
bt_3.png 14KB
bg_cell_imageview@2x.png 1KB
bt_7.png 14KB
bt_4.png 14KB
HelloWorld.png 136KB
bt_5.png 14KB
bt_10@2x.png 45KB
bt_selected_6@2x.png 49KB
bg_center@2x.png 64KB
bt_selected_1.png 15KB
bt_selected_1@2x.png 44KB
bt_11@2x.png 43KB
bt_11.png 14KB
bt_5@2x.png 44KB
bt_selected_5@2x.png 48KB
bg_cell_imageview.png 749B
bt_selected_9.png 16KB
Classes
AppDelegate.h 955B
HelloWorldScene.h 774B
AppDelegate.cpp 1KB
HelloWorldScene.cpp 6KB
共 74 条
- 1
阿木木_411
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页