예제 #1
0
// on "init" you need to initialize your instance
bool HelloWorldScene::init()
{
	//////////////////////////////
	// 1. super init first
	if (!LayerColor::initWithColor(Color4B(255, 255, 255, 255)))
	{
		return false;
	}

	auto cache = SpriteFrameCache::getInstance();
	// enemy의 스프라이트 시트의 위치정보 파일을 읽어들인다.
	cache->addSpriteFramesWithFile("Images/Enemy/Small/Enimies.plist");
	// 플레이어의 스프라이트 시트의 위치정보 파일을 읽어들인다.
	cache->addSpriteFramesWithFile("Images/Player/Player.plist");
	// player shoot 스프라이트 시트의 정보파일 읽기
	cache->addSpriteFramesWithFile("Images/Bullet/PlayerShoot.plist");
	// enemy shoot 스프라이트 시트의 정보파일 읽기
	cache->addSpriteFramesWithFile("Images/Bullet/EnemyShoot.plist");



	// background
	auto back = Sprite::create("Images/StageBackground/main.png");
	back->setPosition(Vec2(1100, 900));
	back->setScale(2.0f);
	this->addChild(back);

	// background action 
	auto action = Sequence::create(MoveTo::create(10.0f, Vec2(150, 200)), MoveTo::create(10.0f, Vec2(1100,900)),  nullptr);
	auto repeat = RepeatForever::create(action);
	back->runAction(repeat);

	// title
	auto title = Label::create("nGaurdian", "Marker Felt", 30);
	title->setScale(3.0f);
	title->setPosition(Vec2(WIN_WIDTH / 2, WIN_HEIGHT * 0.7));
	this->addChild(title);

	// start
	//menu = LabelBMFont::create("Press Start", "font/futura-48.fnt");
	menu = Label::create("Press Start", "Marker Felt", 40);
	menu->setScale(2.0f);
	menu->setPosition(Vec2(WIN_WIDTH / 2, WIN_HEIGHT * 0.3));
	this->addChild(menu);
	
	// menu action
	auto menuAction = Sequence::create(MoveBy::create(1.0f, Vec2(0, 50)), MoveBy::create(1.0f, Vec2(0, -50)), nullptr);
	auto menuRepeat = RepeatForever::create(menuAction);
	menu->runAction(menuRepeat);

	// touch event 들록
	// 터치 이벤트 등록
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(HelloWorldScene::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(HelloWorldScene::onTouchMoved, this);
	listener->onTouchEnded = CC_CALLBACK_2(HelloWorldScene::onTouchEnded, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	return true;
}
예제 #2
0
//************************************
// Method:    initPlist
// FullName:  GameScene::initPlist
// Access:    public
// Returns:   void
// Qualifier:
//************************************
void GameScene::initPlist()
{
    auto sprite_cache = SpriteFrameCache::getInstance();
    sprite_cache->addSpriteFramesWithFile(game_map_plist);
    sprite_cache->addSpriteFramesWithFile(game_planes_plist);
    sprite_cache->addSpriteFramesWithFile(game_bullet_plist);//bullet
    sprite_cache->addSpriteFramesWithFile(game_player_bullet_plist);
}
예제 #3
0
void AppDelegate::preload_sprites()
{
    auto cache = SpriteFrameCache::getInstance();


    CCLOG("start loading sprites");
	cache->addSpriteFramesWithFile("master.plist");
	cache->addSpriteFramesWithFile("master_ui.plist");
    CCLOG("done loading sprites");

};
예제 #4
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	/*
	1.Super init
	*/
    if ( !Layer::init() )
    {
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	FileUtils::getInstance()->addSearchPath("res");

	auto bgPic = Sprite::create("splash_bg.jpg");
	bgPic->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2));
	this->addChild(bgPic);

	/*
	版权信息文件
	text01、02:原本中的官方名字和其他文字
	text03、04:GGSnail声明,仅限个人交流,禁止用于商业用途。
	*/

	auto text01 = Label::createWithTTF("TTZ STUDIO", "fonts/din-light.ttf", 24);
	text01->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height*0.2));
	this->addChild(text01);
	auto text02 = Label::createWithTTF("HAVE MORE FUN", "fonts/din-light.ttf", 24);
	text02->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height*0.2 - 28));
	text02->setTextColor(Color4B(102, 204, 153, 255));
	this->addChild(text02);
	auto text03 = Label::createWithTTF("GGSnail: The exchange of personal use only.", "fonts/din-light.ttf", 24);
	text03->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height*0.2 - 56));
	this->addChild(text03);
	auto text04 = Label::createWithTTF("DO NOT USED FOR COMMERCIAL PURPOSES.", "fonts/din-light.ttf", 24);
	text04->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height*0.2 - 82));
	this->addChild(text04);


	/*
	资源预加载
	sources preload
	*/
	auto cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("res/res_1.plist", "res/res_1.png");
	cache->addSpriteFramesWithFile("res/res_2.plist", "res/res_2.png");
	cache->addSpriteFramesWithFile("res/other.plist", "res/other.png");
	cache->addSpriteFramesWithFile("res/about.plist", "res/about.png");

	//CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("music/bg.mp3");
	//HelloWorld::HelloWorld();
    return true;
}
예제 #5
0
PlaneLayer::PlaneLayer()
{
	Layer::init();

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	auto spriteFrameCache = cocos2d::SpriteFrameCache::sharedSpriteFrameCache(); 
	spriteFrameCache->addSpriteFramesWithFile("shoot.plist");

	auto plane = Sprite::createWithSpriteFrame(spriteFrameCache->spriteFrameByName("hero1.png"));
	plane->setPosition(ccp(winSize.width/2, plane->getContentSize().height/2));
	addChild(plane,1,PlaneSpriteTag);

	Blink* blink = Blink::create(1,3);

	CCAnimation* animation = CCAnimation::create();
	animation->setDelayPerUnit(0.1);
	animation->addSpriteFrame(spriteFrameCache->spriteFrameByName("hero1.png"));
	animation->addSpriteFrame(spriteFrameCache->spriteFrameByName("hero2.png"));

	CCAnimate* animate = CCAnimate::create(animation);

	plane->runAction(blink);
	plane->runAction(CCRepeatForever::create(animate));
}
예제 #6
0
Animation* CommonLib::genarelAnimation(const char* plistFile,const char* spriteFrameName,float delayPerUnit,int loopNum)
{
    Animation* animation=AnimationCache::getInstance()->getAnimation(spriteFrameName);
    if (animation)
        return animation;
    
    auto spriteFrameCache=SpriteFrameCache::getInstance();
    if (strlen(plistFile)>0)
    {
        spriteFrameCache->addSpriteFramesWithFile(plistFile);
    }
    int frameNum=10000;
    Vector<SpriteFrame*> arrayOfSpriteFrames;
    for (int i=1; i<frameNum; ++i)
    {
        char spriteFullName[64]={};
        sprintf(spriteFullName, "%s%d.png",spriteFrameName,i);
        auto spriteFrame=spriteFrameCache->getSpriteFrameByName(spriteFullName);
        if (spriteFrame==nullptr)
        {
//            CCLOG("COMPLETE spriteFrame spriteFullName=%s",spriteFullName);
            break;
        }
        arrayOfSpriteFrames.pushBack(spriteFrame);
    }
    animation=Animation::createWithSpriteFrames(arrayOfSpriteFrames, delayPerUnit,loopNum);
    AnimationCache::getInstance()->addAnimation(animation, spriteFrameName);
    return animation;
}
예제 #7
0
bool Enemy::init_sprite(const Vec2 init_pos)
{
	if (!Sprite::initWithFile(ENEMY_FILENAME))
		return false;

	_speed_x = ENEMY_SPEED_X;
	this->setPosition(init_pos);

	// idle action
	auto frames_cache = SpriteFrameCache::getInstance();
	frames_cache->addSpriteFramesWithFile("enemy_anim.plist");
	auto sprite_sheet = SpriteBatchNode::create("enemy_anim.png");
	this->addChild(sprite_sheet);
	std::string idle_frame_name;
	Vector<SpriteFrame *> idle_anim_frames;
	for (int i = 1; i <= 4; i++)
	{
		idle_frame_name = "enemy_idle_" + std::to_string(i) + ".png";
		SpriteFrame *frame = frames_cache->getSpriteFrameByName(idle_frame_name);
		idle_anim_frames.pushBack(frame);
	}
	Animation *idle_animation = Animation::createWithSpriteFrames(idle_anim_frames, 0.25f);
	_idle = RepeatForever::create(Animate::create(idle_animation));
	this->createWithSpriteFrameName("enemy_idle_1.png");
	this->runAction(_idle);

	this->schedule(schedule_selector(Enemy::shoot), ENEMY_SHOOT_TIME);

	return true;
}
예제 #8
0
// on "init" you need to initialize your instance
bool StatusDisplay::init(GameState* gameState)
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    glview->setDesignResolutionSize(320, 480, ResolutionPolicy::SHOW_ALL);
    
    Size visibleSize = director->getVisibleSize();
    Vec2 origin = director->getVisibleOrigin();
    
    auto spriteCache = SpriteFrameCache::getInstance();
    spriteCache->addSpriteFramesWithFile("sprites_default.plist");
    
    auto player = Sprite::createWithSpriteFrameName("mario_00.png");
    player->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2 - player->getContentSize().height));
    addChild(player);
    auto action = Sequence::create(DelayTime::create(1), CallFunc::create([gameState](){Director::getInstance()->replaceScene(HelloWorld::createScene(gameState));}), NULL);
    
    runAction(action);
    return true;
}
예제 #9
0
Truck * Truck::create(Vec2 position, GameStates & gameState)
{
	std::shared_ptr<GameData> ptr = GameData::sharedGameData();

	auto spritecache = SpriteFrameCache::getInstance();
	spritecache->addSpriteFramesWithFile(ptr->m_textureAtlasPlistFile);		

	Truck* pSprite = new Truck(gameState);
	if (pSprite->initWithSpriteFrameName(ptr->m_truck))
	{
		pSprite->autorelease();

		pSprite->initOptions(position);

		cocos2d::Size size(70, 200);
		auto towerBody = PhysicsBody::createBox(size);
		towerBody->setCollisionBitmask(0x000002);
		towerBody->setContactTestBitmask(true);
		//towerBody->setDynamic(false);

		pSprite->setPhysicsBody(towerBody);

		return pSprite;
	}

	CC_SAFE_DELETE(pSprite);
	return NULL;
}
예제 #10
0
bool AppDelegate::applicationDidFinishLaunching() {
	// initialize random seed
	srand(time(0));

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("Kid Sudoku");
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    register_all_packages();

    auto cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile(DEFAULT_SPRITE);

	DataFileHelper::getInstance()->installPackedData();
    GameController::getInstance()->enterScene(GameController::SceneType::eMainScene);

    return true;
}
예제 #11
0
파일: MayBay.cpp 프로젝트: tinyit/planeTap
MayBay * MayBay::Create(){
    MayBay * obj = new MayBay();
    auto SpFrameCache = SpriteFrameCache::getInstance();
    SpFrameCache->addSpriteFramesWithFile("plane/plane.plist");
    if(!obj->initWithSpriteFrame(SpFrameCache->getSpriteFrameByName("planeRed1.png"))){
        CCLOG("Cant not create maybay");
    }
    else{
        Vector<SpriteFrame*> vecFrm(3);
        char str[50]={0};
        for(int i=1; i<=3 ;i++){
            sprintf(str,"planeRed%d.png",i);
            auto spFrm = SpFrameCache->getSpriteFrameByName(str);
            vecFrm.pushBack(spFrm);
            
        }
        auto animation = Animation::createWithSpriteFrames(vecFrm,0.1f);
        auto ani= Animate::create(animation);
        obj->runAction(RepeatForever::create(ani));
    }
    auto physic = PhysicsBody::createBox(Size(Vec2(obj->getContentSize().width-10,obj->getContentSize().height-10)),PhysicsMaterial(1,0,1));
    physic->setCollisionBitmask(0x001);
    physic->setCategoryBitmask(0x001);
    physic->setContactTestBitmask(true);
    physic->setTag(10);
    obj->setPhysicsBody(physic);
    obj->getPhysicsBody()->setGravityEnable(false);
    obj->setFly();
    return obj;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    auto cache=SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("anim.plist");
    Vector<SpriteFrame*> vec;
    char name[15];
    memset(name,0,15);
    for(int i=0;i<20;i++){
        sprintf(name,"anim%04d",i);
        vec.pushBack(cache->getSpriteFrameByName(name));
    }
    
    Animation *animation=Animation::createWithSpriteFrames(vec,0.1f);
    Animate *animate=Animate::create(animation);
    
    auto sprite=Sprite::create();
    addChild(sprite);
    sprite->setPosition(200,200);
    sprite->runAction(RepeatForever::create(animate));
    return true;
}
예제 #13
0
void Llama::preloadResources(){
    
    //Cache de sprites
    auto spriteFrameCache = SpriteFrameCache::getInstance();
    //Cache de animaciones
    auto animCache = AnimationCache::getInstance();
    
    //Si no estaba el spritesheet en la caché lo cargo
    
    if(!spriteFrameCache->getSpriteFrameByName("fuego1.png")) {
        spriteFrameCache->addSpriteFramesWithFile(OBJETOS_PLIST);
    }
    
    m_anim = Animation::create();
    
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego1.png"));
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego2.png"));
    
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego3.png"));
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego4.png"));
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego5.png"));
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego6.png"));
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego7.png"));
    m_anim->addSpriteFrame(spriteFrameCache->getSpriteFrameByName("fuego8.png"));
    
    m_anim->setDelayPerUnit(.15f);
    m_anim->retain();
    
    animCache->addAnimation(m_anim, "Llama");
    
}
bool CCActivityIndicator::init()
{
    auto spritecache = SpriteFrameCache::getInstance();
    
    spritecache->addSpriteFramesWithFile("ccactivityindicator.plist");
    CCSpriteBatchNode::initWithFile("ccactivityindicator.png", 1);
    
    Size winSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    indicator = CCSprite::createWithSpriteFrameName("ccactivityindicator_1.gif");
    indicator->setPosition(Vec2(winSize.width/2,winSize.height/2));
    addChild(indicator);
    
    animating = false;
    hidesWhenStopped = true;
    
//    beginCallback = NULL;
//    endCallback =


    //load all sprite frames into array
    for (int i=1; i<=kActivityIndicatorFramesCount; i++) {
        SpriteFrame * frame = spritecache->getSpriteFrameByName(CCString::createWithFormat("ccactivityindicator_%d.gif",i)->getCString());
        frame->retain();
        spriteFrames.pushBack(frame);
    }
    
    return true;
}
예제 #15
0
Coin * Coin::create(Vec2 position, GameStates & gameState)
{
	std::shared_ptr<GameData> ptr = GameData::sharedGameData();

	auto spritecache = SpriteFrameCache::getInstance();
	spritecache->addSpriteFramesWithFile(ptr->m_textureAtlasPlistFile);		

	Coin* pSprite = new Coin(gameState);
	if (pSprite->initWithSpriteFrameName(ptr->m_coinFile))
	{
		pSprite->autorelease();
		

		pSprite->initOptions(position);

		pSprite->addEvents();
		pSprite->setTag(30);

		auto towerBody = PhysicsBody::createBox(pSprite->getContentSize());
		towerBody->setCollisionBitmask(0x000003);
		towerBody->setContactTestBitmask(true);
		towerBody->setTag(30);
		//towerBody->setDynamic(false);

		pSprite->setPhysicsBody(towerBody);

		return pSprite;
	}

	CC_SAFE_DELETE(pSprite);
	return NULL;
}
예제 #16
0
bool AppDelegate::applicationDidFinishLaunching() {
    // load config
    auto config = Configuration::getInstance();
    config->loadConfigFile("config/words.plist");
    
    // init word data
    Constants::initWordData();
    
    // random seed
    srand( unsigned( time(0) ) );
    
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }
    
    auto screenSize = glview->getFrameSize();
    auto designSize = Size(320, 480);
    
    std::vector<std::string> searchPaths;
    if (screenSize.height > 960)
    {
        searchPaths.push_back("HDR");
        searchPaths.push_back("HD");
        searchPaths.push_back("SD");
        director->setContentScaleFactor(4.0f);
    }
    else if (screenSize.height > 480)
    {
        searchPaths.push_back("HD");
        searchPaths.push_back("SD");
        director->setContentScaleFactor(2.0f);
    }
    else
    {
        searchPaths.push_back("SD");
        director->setContentScaleFactor(1.0f);
    }
    
    FileUtils::getInstance()->setSearchPaths(searchPaths);
    auto cacher = SpriteFrameCache::getInstance();
    cacher->addSpriteFramesWithFile("assets.plist");
    
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    auto scene = HelloWorld::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
예제 #17
0
void Tutorial::Crash()// draws the animation for a crash and pasticles that fly out from there
{
	//animation code
	auto spritecache = SpriteFrameCache::getInstance();
	spritecache->addSpriteFramesWithFile("GameScreen/explosion.plist");
	cocos2d::SpriteFrame* spriteFrame = spritecache->getSpriteFrameByName("explosion0.png");
	cocos2d::Vector<cocos2d::Sprite *> m_aiSprites;
	cocos2d::Vector<cocos2d::SpriteFrame*> m_animFrames;
	for (int i = 0; i < 23; i++)
	{
		// Get a SpriteFrame using a name from the spritesheet .plist file.
		m_animFrames.pushBack(spritecache->getSpriteFrameByName("explosion" + std::to_string(i) + ".png"));
	}
	// Create the animation out of the frames.
	Animation* animation = Animation::createWithSpriteFrames(m_animFrames, 0.065);
	Animate* animate = Animate::create(animation);
	// Create a sprite using any one of the SpriteFrames
	// This is so we get a sprite of the correct dimensions.
	auto sprite = Sprite::createWithSpriteFrame(m_animFrames.at(0));
	// Run and repeat the animation.
	sprite->setScale(3.0f);
	sprite->runAction(RepeatForever::create(animate));
	sprite->setPosition(Vec2(player->getPosition().x, player->getPosition().y - 5));
	this->addChild(sprite, 10);
	m_aiSprites.pushBack(sprite);


	//code for the particles that will be coloured orange
	auto size = Director::getInstance()->getWinSize();
	auto m_emitter = ParticleExplosion::createWithTotalParticles(900);
	m_emitter->setDuration(-1);
	m_emitter->setGravity(Point(0, -240));
	m_emitter->setAngle(0);
	m_emitter->setAngleVar(180);
	m_emitter->setRadialAccel(25);
	m_emitter->setRadialAccelVar(0);
	m_emitter->setTangentialAccel(10);
	m_emitter->setTangentialAccelVar(0);
	m_emitter->setPosVar(Point(1, 0));
	m_emitter->setLife(0.25);
	m_emitter->setLifeVar(0.50);
	m_emitter->setStartSpin(0);
	m_emitter->setStartSpinVar(0);
	m_emitter->setEndSpin(0);
	m_emitter->setEndSpinVar(0);
	m_emitter->setStartColor(Color4F(212, 73, 0, 1));
	m_emitter->setStartColorVar(Color4F(0, 0, 0, 0));
	m_emitter->setEndColor(Color4F(212, 73, 0, 1));
	m_emitter->setEndColorVar(Color4F(0, 0, 0, 0));
	m_emitter->setStartSize(20.0f);
	m_emitter->setStartSizeVar(0);
	m_emitter->setEndSize(15.0f);
	m_emitter->setEndSizeVar(0);
	m_emitter->setEmissionRate(275);
	m_emitter->setPosition(Vec2(player->getPosition().x, player->getPosition().y - 15));
	addChild(m_emitter, 10);
}
예제 #18
0
dropItem* dropItem::create(Layer* l) {
    dropItem* di = new dropItem();
    di->mark = 0;
    auto cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile(PLIST_DROPITEM);
    di->layer = l;
    di->dropMark = UserData::getInstance()->stageCount*1500;
    return di;
}
예제 #19
0
BulletBase *BulletFactory::createBullet(const int &rBulletId, TowerBase* rTower, VictimEntityBase *rVictimEntity)
{
	auto cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("Themes/Towers/TBottle-hd.plist", "Themes/Towers/TBottle-hd.png");
	cache->addSpriteFramesWithFile("Themes/Towers/TFan-hd.plist", "Themes/Towers/TFan-hd.png");
	cache->addSpriteFramesWithFile("Themes/Towers/TShit-hd.plist", "Themes/Towers/TShit-hd.png");

    auto pBullet = BulletBase::create(rBulletId, rVictimEntity);
	pBullet->setRotation(90 - 180 * (rVictimEntity->getPosition() - rTower->getPosition()).getAngle() / M_PI);
	if (pBullet->getIBulletType() == en_GunBullet){
		pBullet->setPosition(rTower->getPosition() + Vec2(36 * sin(pBullet->getRotation() * M_PI / 180), 36 * cos(pBullet->getRotation() * M_PI / 180)));
	}else{
		pBullet->setPosition(rTower->getPosition());
	}
	
	pBullet->doMove();

    return pBullet;
}
예제 #20
0
void LoadResourceLayer::loadPlists()
{
    auto frameCache = SpriteFrameCache::getInstance();
    for (const auto& file:_plists)
    {
        frameCache->addSpriteFramesWithFile(file);
        _finish++;
        _targetValue = 100.0f * _finish / _resourceAmount;
        _speed = (_targetValue - _currValue) * 5;
    }
}
예제 #21
0
bool HelloWorld::init()
{
    if ( !LayerColor::initWithColor(Color4B(255, 255, 255, 255) ))
    {
        return false;
    }

	auto cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("Images/grossini_family.plist");

	cache->addSpriteFramesWithFile("Images/grossini.plist");

	auto pSprite = SpriteFrame::create("Images/blocks9.png", Rect(0, 0, 96, 96));
	cache->addSpriteFrame(pSprite, "blocks9.png");

	auto pWoman = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
	pWoman->setPosition(Vec2(120, 220));
	this->addChild(pWoman);

	auto pMan = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
	pMan->setPosition(Vec2(240, 220));
	this->addChild(pMan);

	auto pBox = Sprite::createWithSpriteFrameName("blocks9.png");
	pBox->setPosition(Vec2(3660, 220));
	this->addChild(pBox);

	auto texture = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png");
	auto pMan2 = Sprite::createWithTexture(texture, Rect(0, 0, 85, 121));
	pMan2->setPosition(Vec2(120, 100));
	this->addChild(pMan2);

	texture = Director::getInstance()->getTextureCache()->addImage("Images/dragon_animation.png");
	auto pDragon = Sprite::createWithTexture(texture, Rect(0, 0, 130, 140));
	pDragon->setPosition(Vec2(240, 100));
	this->addChild(pDragon);

	Director::getInstance()->getTextureCache()->addImageAsync("Images/blocks9.png", CC_CALLBACK_1(HelloWorld::imageLoaded, this));
    
	return true;
}
예제 #22
0
Animation* AnimationManager::getImageAnimationWithPlist(char *plist, char *format, USIZE nStart, USIZE nEnd, char *imagePath)
{
    auto cache = SpriteFrameCache::getInstance();
    
	if (imagePath)
		cache->addSpriteFramesWithFile(plist, imagePath);
    else
        cache->addSpriteFramesWithFile(plist);
    
    auto animation = Animation::create();
    animation->retain();
    
    for (USIZE i = nStart; i <= nEnd; ++i)
    {
        auto path = String::createWithFormat(format, i)->getCString();
        auto frame = cache->getSpriteFrameByName(path);
        animation->addSpriteFrame(frame);
    }
    
    return animation;
}
예제 #23
0
void AnimationManager::loadHeroAnimation(const char *plist) {
    auto cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile(plist);
    auto animation = Animation::create();
    for (int i = 1; i < 3; i++)
    {
        auto filename = StringUtils::format("mainplaneIdle%d.png", i);
        animation->addSpriteFrame(cache->getSpriteFrameByName(filename));
    }
    animation->setDelayPerUnit(0.1f);
    animation->setLoops(-1);
    m_manager->addAnimation(animation, "hero-normal");
}
예제 #24
0
void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName)
{
	CCAssert(textureFileName, "texture name should not be null");
	CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(textureFileName);

	if (texture)
	{
		addSpriteFramesWithFile(plist, texture);
	}
	else
	{
		CCLOG("cocos2d: CCSpriteFrameCache: couldn't load texture file. File not found %s", textureFileName);
	}
}
예제 #25
0
파일: Bullet.cpp 프로젝트: baokuanze/Zoom
//子弹
void Bullet::creatPeaBullet(Point p,Layer *layer){
    log("dddd");
    auto cache=SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("PeashooterBullet_default.plist");
    this->initWithSpriteFrameName("PeashooterBullet-1(被拖移).tiff");
    this->setPosition(p.x+10,p.y+10);
    this->setScale(0.5);
    layer->addChild(this);
    float distance=500-this->getPosition().x;
    float time=distance/200;
    auto call=CallFuncN::create(CC_CALLBACK_1(Bullet::removeBullet, this));
    auto moveto=MoveTo::create(time, Vec2(500, this->getPosition().y));
    auto sequence=Sequence::create(moveto,call, NULL);
    this->runAction(sequence);
}
void TextureLoadingManager::TextureLoadingCallback(Texture2D *texture, const std::string& plistName)
{	
	if (plistName != "None"){
		auto sfc = SpriteFrameCache::getInstance();
		sfc->addSpriteFramesWithFile(plistName, texture);
	}

	_textureCount--;
	_delegate->onTextureLoaded(this);

	if (_textureCount == 0){
		_delegate->onTextureLoadingEnded(this);
		_isRunning = false;
	}
}
예제 #27
0
const std::tuple<
	std::vector<SpriteFrame*>,
	std::map<std::string, std::tuple<int, int> >
>&	
CharacterDataPool::insert(
	const std::string& name,
	const std::string& foldername,
	const std::string& format) 
{
	auto already = _pool.find(name);
	if (already != end(_pool)) {
		return already->second;
	}

	rapidjson::Document json;
	Util::readJSON(foldername + "/" + name + "/data.json", json);

	std::vector<SpriteFrame*> animFrames;
	std::map<std::string, std::tuple<int, int> > actions;

	for (rapidjson::Value::MemberIterator M = json["actions"].MemberBegin(); M != json["actions"].MemberEnd(); M++) {
		std::string key = M->name.GetString();
		actions.insert(std::make_pair(key, std::make_tuple(M->value["frameSize"].GetInt(), 0)));
	}
	
	auto frameCache = SpriteFrameCache::getInstance();
	char number[10] = { 0 };
	int accum = 0;

	for (std::map<std::string, std::tuple<int, int>>::iterator iter = begin(actions); iter != end(actions); iter++) {
		
		std::string filename = foldername + "/" + name + "/" + iter->first + ".plist";
		frameCache->addSpriteFramesWithFile(filename);
		iter->second = std::make_tuple(std::get<0>(iter->second), accum);

		for (int i = 1; i <= DIRECTIONS * std::get<0>(iter->second); i++) {
			sprintf(number, "_%02d.", i);
			std::string tempstr = iter->first + number + format;

			auto frame = frameCache->getSpriteFrameByName(tempstr);
			animFrames.push_back(frame);
		}
		accum += std::get<0>(iter->second) * DIRECTIONS;
	}

	auto result = _pool.insert(std::make_pair(name, std::make_tuple(animFrames, actions)));
	return result.first->second;
}
예제 #28
0
파일: Bird.cpp 프로젝트: operatium/Drup_App
Bird::Bird(const std::string& filename, const std::string& c_plist, const char* c_FileNameFormat, Vec2 P0, Vec2 P1, Vec2 P2, Vec2 P3, float DelayTime, float FlyTime)
{
	auto cache = SpriteFrameCache::getInstance();
	auto frame = cache->spriteFrameByName(filename);
	if (frame == nullptr)
	{
		CCLOG("空=%s", filename.c_str());
		cache->addSpriteFramesWithFile(c_plist);
	}
	this->initWithSpriteFrame(frame);
	m_P0 = P0;
	m_P1 = P1;
	m_P2 = P2;
	m_P3 = P3;
	m_DelayTime = DelayTime;
	m_FlyTime = FlyTime;
	m_FlyAnimation = FrameAnimation::create(4, c_plist, c_FileNameFormat, 0.06f);
}
예제 #29
0
파일: Bullet.cpp 프로젝트: baokuanze/Zoom
//阳关
void Bullet::createSunflashBullet(Point p, Layer *layer){
    auto cache=SpriteFrameCache::getInstance();
    char temp[50]="Sun_default.plist";
    cache->addSpriteFramesWithFile("Sun_default.plist", "Sun_default.png");
    this->initWithSpriteFrameName("Sun-1(被拖移).tiff");
    this->setScale(0.4);
    __Dictionary *dic=__Dictionary::createWithContentsOfFile(temp);
    __Dictionary *dic2=(__Dictionary*)dic->objectForKey("frames");
    int num=(int)dic2->allKeys()->count();
    Vector<SpriteFrame *>vect;
    for ( int i=1; i<=num; i++) {
        std:: string str=StringUtils::format("Sun-%d(被拖移).tiff",i);
        auto frame=cache->getSpriteFrameByName(str);
        vect.pushBack(frame);
    }
    auto animation=Animation::createWithSpriteFrames(vect,0.1);
    auto animate=Animate::create(animation);
    this->runAction(RepeatForever::create(animate));

    auto spriteItem=MenuItemSprite::create(this,this,[layer](Ref *sender){
        auto sprite=static_cast<MenuItemSprite*>(sender);
        auto move=MoveTo::create(1, Vec2(55, 320));
        
        auto call=CallFuncN::create([layer](Node *sen){
            sen->removeFromParent();
            //移除之后将获得lable的值进行相加+50
            auto laye=(GameScene *)layer;
            auto lable=laye->lable;
            int a= atoi( lable->getString().c_str())+50;
            std::string str=StringUtils::format("%d",a);
            lable->setString(str);
        });
        
        auto sequence=Sequence::create(move,call, NULL);
        auto menu= sprite->getParent();
        menu->runAction(sequence);
    });
    
    auto menu=Menu::create(spriteItem, NULL);
    menu->setPosition(p.x+20,p.y+25);
    layer->addChild(menu);
    auto jump=JumpTo::create(1, Vec2(p.x-5,p.y-5), 30, 1);
    menu->runAction(jump);
}
예제 #30
0
파일: Guard.cpp 프로젝트: ilhaeYe/MB
Guard* Guard::create()
{
	auto pSprite = new Guard();
	pSprite->SetMonsterData();

	auto cache = SpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile(
		String::createWithFormat("%s/%s/%sImage.plist", pSprite->getType().c_str(), pSprite->getName().c_str(), pSprite->getName().c_str())->getCString(),
		String::createWithFormat("%s/%s/%s.png", pSprite->getType().c_str(), pSprite->getName().c_str(), pSprite->getName().c_str())->getCString()
		);
	if (pSprite->initWithSpriteFrameName(String::createWithFormat("%s.png", pSprite->getName().c_str())->getCString()))
	{
		pSprite->autorelease();
		pSprite->InitSprite();
		return pSprite;
	}
	CC_SAFE_DELETE(pSprite);
	return NULL;
}