Skip to content

Instantly share code, notes, and snippets.

@tks2shimizu
Created September 8, 2014 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tks2shimizu/12bdd010d77ba7e9b3bb to your computer and use it in GitHub Desktop.
Save tks2shimizu/12bdd010d77ba7e9b3bb to your computer and use it in GitHub Desktop.
シューティングゲームを作ろう!(2)背景のアニメーション
#include "GameLayer.h"
USING_NS_CC;
//シーン作成
Scene* GameLayer::createScene()
{
auto scene = Scene::create();
auto layer = GameLayer::create();
scene->addChild(layer);
return scene;
}
//初期化
bool GameLayer::init()
{
if (!Layer::init())
return false;
//背景を表示
initBackground();
return true;
}
//背景を表示
void GameLayer::initBackground()
{
//画面サイズの取得
Size winSize = Director::getInstance()->getWinSize();
//背景の生成
auto background = Sprite::create("Background.png");
//背景のアンカーポイント設定
background->setAnchorPoint(Vec2(0.5, 0));
//背景の位置設定
background->setPosition(Vec2(winSize.width / 2, 0));
//背景の追加
addChild(background, Z_Bg);
//アニメーションの作成
auto movePosition = Vec2(winSize.width / 2, winSize.height - background->getContentSize().height);
auto move = MoveTo::create(120, movePosition);
//アニメーションの実行
background->runAction(move);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment