bool SampleScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Scene::init() )
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("pipo-charachip001b.png");
if (sprite == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
}
return true;
}
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("pipo-charachip001b.png", Rect(0,0,32,32));
if (sprite == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
}
auto sprite2 = Sprite::create("pipo-charachip001b.png", Rect(0,32,32,32));
if (sprite2 == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite2->setPosition(Vec2(visibleSize.width/2 + origin.x + sprite->getContentSize().width, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite2, 0);
}
return true;
じゃあ、これを使って、アニメーションさせます。
auto sprite = Sprite::create("pipo-charachip001b.png");
if (sprite == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
}
Vector<SpriteFrame*> animFrames;
animFrames.reserve(12);
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,0,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,0,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,0,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,32,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,32,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,32,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,64,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,64,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,64,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,96,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,96,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,96,32,32)));
Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
Animate* animate = Animate::create(animation);
sprite->runAction(RepeatForever::create(animate));
auto moveBy = MoveBy::create(2, Vec2(50, 0));
sprite->runAction(moveBy);
return true;
class GameData
{
public enum GameStatus
{
None,
SelectCity,
ActionEnemy,
ActionPlayer,
ShowResult,
GameEnd,
GameOver
}
public GameStatus gameStatus = GameStatus.None;
public List<City> Cities = null;
public List<City> AliveCities = null;
public Battle Battle = null;
public Player Player = null;
このクラスはシングルトンで管理します。
class Singleton
{
private static GameData _gameData = null;
public static GameData GetGameData()
{
if (_gameData == null)
{
_gameData = new GameData();
}
return _gameData;
}
このシングルトンクラス、ゲッターのでいいんじゃないかと思い始めた。
やっていることは同じですが。
メソッドでやるか、プロパティでやるかの違いです。
気が向いたら直します。
シーン遷移は全てシーンクラスのインスタンスを作り直します。
if (asd.Engine.Mouse.LeftButton.ButtonState == asd.ButtonState.Push)
{
var scene = new MainScene();
asd.Engine.ChangeScene(scene);
}