コード例 #1
0
ファイル: FlashDemo.cs プロジェクト: kyallbarrows/Cinch2D_4.3
    public override void OnAwake()
    {
        CreateBackground();

        //make the start button and add it to the stage
        CinchSprite startButton = CinchSprite.NewFromImage("StartButton");

        this.AddChild(startButton);
        startButton.Width  = 3f;
        startButton.ScaleY = startButton.ScaleX;

        //give it a jaunty little tilt
        startButton.Rotation = 10f;

        //do an animation effect and start the game when startButton is pressed
        startButton.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, (mouseEvent) => {
            new Tween(startButton, "ScaleX",
                      1.5f, .5f, Easing.Bounce.EaseOut, 0f);
        });

        //add an instructions text field
        SimpleTextField instructions = SimpleTextField.NewFromString("Press Start to begin!", "FjallaOne-Regular", .4f, TextAnchor.MiddleCenter);

        this.AddChildAt(instructions, 1);

        startButton.X  = ViewportWidth / 2;
        startButton.Y  = ViewportHeight / 2;
        instructions.X = startButton.X;
        instructions.Y = startButton.Y - 1.4f;
    }
コード例 #2
0
ファイル: UsingClocks.cs プロジェクト: kyallbarrows/Cinch_4-3
    public override void OnAwake()
    {
        CreateBackground();

        //Create a container for "GamePlay" (a bunch of floating berries)
        _gameplayContainer = Library.New<CinchSprite>("StrawberriesContainer");
        AddChild(_gameplayContainer);

        //pausing this Clock will pause all children
        _gameplayContainer.Clock = new GameClock("GameplayClock");

        //Create 15 FloatingStrawberry's
        for (var i=0; i<7000; i++)
        {
            _gameplayContainer.AddChild(Library.New<FloatingStrawberry>("Berry" + Random.Range (1, 1000)));
        }

        //Create a button to pause gameplay
        _pause = CinchSprite.NewFromImage("Cinch2D/Pause");
        AddChild(_pause);
        //SetPosition is faster than setting X and Y individually, since X and Y each cause display chain updates
        _pause.SetPosition(ViewportWidth/2 - _pause.Width, ViewportHeight/2 - _pause.Height);
        _pause.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, Pause);

        //Create a button to start gameplay
        _play = CinchSprite.NewFromImage("Cinch2D/Play");
        AddChild(_play);
        _play.SetPosition(ViewportWidth/2 - _play.Width, ViewportHeight/2 - _play.Height);
        _play.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, Play);
        _play.Visible = false;
    }
コード例 #3
0
    // Use this for initialization
    public override void OnAwake()
    {
        CinchOptions.DefaultPixelsPerMeter = 25f;

        Stage.Instance.TheCamera.backgroundColor = new Color(.2f, .2f, .2f, 1f);
        _joesContainer = Library.New<CinchSprite>("Joes Container");
        AddChild(_joesContainer);
        _joesContainer.X = Stage.Instance.ViewportWidth/2;
        _joesContainer.Y = Stage.Instance.ViewportHeight/2;
        _joesContainer.Clock = new GameClock("JoesContainerClock");

        _play = CinchSprite.NewFromImage("Play", 100f);
        _pause = CinchSprite.NewFromImage("Pause", 100f);
        AddChild(_play);
        AddChild(_pause);
        _play.Visible = false;
        _play.X = _pause.X = ViewportWidth - .5f;
        _play.Y = _pause.Y = ViewportHeight - .5f;

        _play.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onPlayPress);
        _pause.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onPausePress);

        _joes = new List<CinchSprite>();
        for (var i=0; i < 15; i++)
        {
            var joe = CreateJoe();
            _joes.Add (joe);
            joe.ScaleX = -1;
        }
    }
コード例 #4
0
    public override void OnAwake()
    {
        CreateBackground();

        _cardsContainer = Library.New<CinchSprite>("CardsContainer");
        AddChild(_cardsContainer);
        _cardsContainer.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, MoveCardToTop);

        float cardWidth = 100f;
        float cardHeight = 128f;

        CinchOptions.DefaultPixelsPerMeter = 100f;
        for (var number = 0; number < 5; number++)
        {
            for (var suit = 0; suit < 4; suit++){
                //even though the coordinate system is bottom up, sprite sheets default to top-down coordinates
                //this can be reversed by setting CinchOptions.UseTopLeftSpriteSheetCoordinates = false
                var left = number * cardWidth;	//move from left to right 100 px at a time
                var top = suit * cardHeight;	//move top to bottom 128 px at a time
                var pixPerMeter = 100f;

                var newCard = CinchSprite.NewFromSpriteSheet("Cinch2D/PlayingCards", left, top, cardWidth, cardHeight, pixPerMeter);
                _cardsContainer.AddChild(newCard);

                //give the cards random positions and rotations
                newCard.X = ViewportWidth * Random.Range(-.4f, .4f);
                newCard.Y = ViewportHeight * Random.Range(-.4f, .4f);
                newCard.RotationDegrees = Random.Range (-45f, 45f);
            }
        }
    }
コード例 #5
0
    public override void OnAwake()
    {
        CreateBackground();

        _cardsContainer = Library.New <CinchSprite>("CardsContainer");
        AddChild(_cardsContainer);
        _cardsContainer.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, MoveCardToTop);

        float cardWidth  = 100f;
        float cardHeight = 128f;

        CinchOptions.DefaultPixelsPerMeter = 100f;
        for (var number = 0; number < 5; number++)
        {
            for (var suit = 0; suit < 4; suit++)
            {
                //even though the coordinate system is bottom up, sprite sheets default to top-down coordinates
                //this can be reversed by setting CinchOptions.UseTopLeftSpriteSheetCoordinates = false
                var left        = number * cardWidth;           //move from left to right 100 px at a time
                var top         = suit * cardHeight;            //move top to bottom 128 px at a time
                var pixPerMeter = 100f;

                var newCard = CinchSprite.NewFromSpriteSheet("Cinch2D/PlayingCards", left, top, cardWidth, cardHeight, pixPerMeter);
                _cardsContainer.AddChild(newCard);

                //give the cards random positions and rotations
                newCard.X = ViewportWidth * Random.Range(-.4f, .4f);
                newCard.Y = ViewportHeight * Random.Range(-.4f, .4f);
                newCard.RotationDegrees = Random.Range(-45f, 45f);
            }
        }
    }
コード例 #6
0
    public override void OnAwake()
    {
        CreateBackground();

        //Create a container for "GamePlay" (a bunch of floating berries)
        _gameplayContainer = Library.New <CinchSprite>("StrawberriesContainer");
        AddChild(_gameplayContainer);

        //pausing this Clock will pause all children
        _gameplayContainer.Clock = new GameClock("GameplayClock");

        //Create 15 FloatingStrawberry's
        for (var i = 0; i < 15; i++)
        {
            _gameplayContainer.AddChild(Library.New <FloatingStrawberry>("Berry" + Random.Range(1, 1000)));
        }

        //Create a button to pause gameplay
        _pause = CinchSprite.NewFromImage("Cinch2D/Pause");
        AddChild(_pause);
        //SetPosition is faster than setting X and Y individually, since X and Y each cause display chain updates
        _pause.SetPosition(ViewportWidth / 2 - _pause.Width, ViewportHeight / 2 - _pause.Height);
        _pause.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, Pause);

        //Create a button to start gameplay
        _play = CinchSprite.NewFromImage("Cinch2D/Play");
        AddChild(_play);
        _play.SetPosition(ViewportWidth / 2 - _play.Width, ViewportHeight / 2 - _play.Height);
        _play.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, Play);
        _play.Visible = false;
    }
コード例 #7
0
    // Use this for initialization
    public override void OnAwake()
    {
        CinchOptions.DefaultPixelsPerMeter = 25f;

        Stage.Instance.TheCamera.backgroundColor = new Color(.2f, .2f, .2f, 1f);
        _joesContainer = Library.New <CinchSprite>("Joes Container");
        AddChild(_joesContainer);
        _joesContainer.X     = Stage.Instance.ViewportWidth / 2;
        _joesContainer.Y     = Stage.Instance.ViewportHeight / 2;
        _joesContainer.Clock = new GameClock("JoesContainerClock");

        _play  = CinchSprite.NewFromImage("Play", 100f);
        _pause = CinchSprite.NewFromImage("Pause", 100f);
        AddChild(_play);
        AddChild(_pause);
        _play.Visible = false;
        _play.X       = _pause.X = ViewportWidth - .5f;
        _play.Y       = _pause.Y = ViewportHeight - .5f;

        _play.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onPlayPress);
        _pause.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onPausePress);

        _joes = new List <CinchSprite>();
        for (var i = 0; i < 15; i++)
        {
            var joe = CreateJoe();
            _joes.Add(joe);
            joe.ScaleX = -1;
        }
    }
コード例 #8
0
    public override void OnAwake()
    {
        base.OnAwake();

        VerifySizingForEmptyObject();
        VerifySizingForEmptyParent();

        if (ViewportWidth > ViewportHeight)
        {
            ViewportWidth = 10f;
        }
        else
        {
            ViewportHeight = 10f;
        }

        _sizeChart      = CinchSprite.NewFromImage("SizeChart", 100f, RegistrationPoint.BottomLeft);
        _sizeChart.Name = "SizeChart";
        _sizeChart.X    = ViewportWidth / -2;
        _sizeChart.Y    = ViewportHeight / -2;
        AddChild(_sizeChart);

        //give it a weird pixels-per-meter to make sure it's not an even width in meters
        _earthContainer = Library.New <DisplayObjectContainer>("EarthContainer");
        _earthContainer.SetPosition(3, 7);
        AddChild(_earthContainer);
        var innerContainer = Library.New <DisplayObjectContainer>("InnerContainer");

        _earthContainer.AddChild(innerContainer);
        var yetAnotherContainer = Library.New <DisplayObjectContainer>("YetAnotherContainer");

        innerContainer.AddChild(yetAnotherContainer);
        var earth = CinchSprite.NewFromImage("Earth", 158f, RegistrationPoint.Center);

        earth.MouseEnabled = true;
        earth.Name         = "Earth";
        earth.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onEarthPress);
        yetAnotherContainer.AddChild(earth);

        //give it a weird pixels-per-meter to make sure it's not an even width in meters
        _mars = CinchSprite.NewFromImage("Mars", 212f, RegistrationPoint.BottomLeft);
        _mars.MouseEnabled = true;
        _mars.Name         = "Mars";
        _mars.SetPosition(.5f, .5f);
        _mars.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onMarsPress);
        AddChild(_mars);
    }
コード例 #9
0
ファイル: SizingStage.cs プロジェクト: kyallbarrows/Cinch_4-3
    public override void OnAwake()
    {
        base.OnAwake();

        VerifySizingForEmptyObject();
        VerifySizingForEmptyParent();

        if (ViewportWidth > ViewportHeight)
            ViewportWidth = 10f;
        else
            ViewportHeight = 10f;

        _sizeChart = CinchSprite.NewFromImage("SizeChart", 100f, RegistrationPoint.BottomLeft);
        _sizeChart.Name = "SizeChart";
        _sizeChart.X = ViewportWidth/-2;
        _sizeChart.Y = ViewportHeight/-2;
        AddChild(_sizeChart);

        //give it a weird pixels-per-meter to make sure it's not an even width in meters
        _earthContainer = Library.New<DisplayObjectContainer>("EarthContainer");
        _earthContainer.SetPosition(3, 7);
        AddChild(_earthContainer);
        var innerContainer = Library.New<DisplayObjectContainer>("InnerContainer");
        _earthContainer.AddChild(innerContainer);
        var yetAnotherContainer = Library.New<DisplayObjectContainer>("YetAnotherContainer");
        innerContainer.AddChild(yetAnotherContainer);
        var earth = CinchSprite.NewFromImage("Earth", 158f, RegistrationPoint.Center);
        earth.MouseEnabled = true;
        earth.Name = "Earth";
        earth.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onEarthPress);
        yetAnotherContainer.AddChild(earth);

        //give it a weird pixels-per-meter to make sure it's not an even width in meters
        _mars = CinchSprite.NewFromImage("Mars", 212f, RegistrationPoint.BottomLeft);
        _mars.MouseEnabled = true;
        _mars.Name = "Mars";
        _mars.SetPosition(.5f, .5f);
        _mars.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onMarsPress);
        AddChild(_mars);
    }