from datetime import datetime
import cv2, os
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
def main():
if cap == None:
return False
out = None
capture = False
while cap.isOpened():
# カメラから映像を読み込む
_, img = cap.read()
cv2.imshow("preview", img)
if capture:
if out != None:
out.write(img)
key = cv2.waitKey(1)
if key == ord('z'):
cv2.imwrite("test.png", img)
if key == ord('x'):
if not capture:
capture = True
out = cv2.VideoWriter('test.avi',fourcc, 20.0, (640,480))
else:
capture = False
out.release()
out = None
elif key < 255:
break
# 事後処理
cap.release()
if out != None:
out.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
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);
}
class SampleScene : public cocos2d::Scene
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(SampleScene);
};
#include "SampleScene.h"
#include "SimpleAudioEngine.h"
USING_NS_CC;
Scene* SampleScene::createScene()
{
return SampleScene::create();
}
// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
printf("Error while loading: %s\n", filename);
printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}
// on "init" you need to initialize your instance
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("HelloWorld.png");
if (sprite == nullptr)
{
problemLoading("'HelloWorld.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;
}
void SampleScene::menuCloseCallback(Ref* pSender)
{
//Close the cocos2d-x game scene and quit the application
Director::getInstance()->end();
/*To navigate back to native iOS screen(if present) without quitting the application ,do not use Director::getInstance()->end() as given above,instead trigger a custom event created in RootViewController.mm as below*/
//EventCustom customEndEvent("game_scene_close_event");
//_eventDispatcher->dispatchEvent(&customEndEvent);
}
// create a scene. it's an autorelease object
auto scene = SampleScene::createScene();
// run
director->runWithScene(scene);
return true;
}
auto str = String();
str.appendWithFormat("visible (%f %f)", visibleSize.width, visibleSize.height);
auto label = Label::createWithTTF(str.getCString(), "fonts/msgothic.ttc", 24);
if (label == nullptr)
{
problemLoading("'fonts/msgothic.ttc'");
}
else
{
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
}
auto str2 = String();
str2.appendWithFormat("origin (%f %f)", origin.x, origin.y);
auto label2 = Label::createWithTTF(str2.getCString(), "fonts/msgothic.ttc", 24);
if (label2 == nullptr)
{
problemLoading("'fonts/msgothic.ttc'");
}
else
{
// position the label on the center of the screen
label2->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height * 2));
// add the label as a child to this layer
this->addChild(label2, 2);
}