Пример #1
0
        public static void DrawSprite(RenderTarget destination,
                                      Vector2f location,
                                      Texture texture,
                                      MyIntRect sub_rect,
                                      Color coloration,
                                      float rotation,
                                      Vector2f scale,
                                      BlendMode blend_mode,
                                      Shader shader)
        {
            sprite.Texture  = texture;
            sprite.Origin   = new Vector2f(sprite.TextureRect.Width / 2.0f, sprite.TextureRect.Height / 2.0f);
            sprite.Scale    = scale;
            sprite.Position = location;


            //sprite.TextureRect = sub_rect;
            sprite.Color    = coloration;
            sprite.Rotation = rotation;                     //rotation-90.0f

            RenderStates rs = new RenderStates(blend_mode); // Transform.Identity, null, shader);



            destination.Draw(sprite, rs);
        }
 public AnimationInfo(Texture texture, IEnumerable <MyIntRect> frames, MyIntRect view_offset, bool repeat = false)
 {
     this.refTexture     = texture; //  assets.GetTexture(texture_name);
     this.Frames         = new List <MyIntRect>(frames);
     this.ViewOffsetRect = view_offset;
     this.Repeat         = repeat;
 }
Пример #3
0
        public void Render(RenderTarget destination, Vector2f pos) //MyIntRect view_rect = new MyIntRect()
        {
            MyIntRect frame = this.GetCurrentFrame().DeepCopy();   //.DeepCopy is very important for drawing!!

            frame.Left += this.animData.ViewOffsetRect.Left;
            frame.Top  += this.animData.ViewOffsetRect.Top;

            frame.Width  = this.animData.ViewOffsetRect.Width;
            frame.Height = this.animData.ViewOffsetRect.Height;

            /*
             * cRenderFunctions.DrawTextureSimple( destination,
             *                                  pos,
             *                                  this.GetSpriteSheet(),
             *                                  frame,
             *                                  Color.White,
             *                                  BlendMode.Alpha
             *  );
             */


            DrawingBase.DrawTexture(destination,
                                    pos,
                                    this.GetTexture(),
                                    frame,
                                    Color.White,
                                    0.0f,
                                    1.0f,  //SCALE_FACTOR,
                                    false, //p_myCurrentAnim->IsFlippedHorizontally(),
                                    false,
                                    BlendMode.Alpha,
                                    null);
        }
Пример #4
0
        public cSpriteRenderer(string texture_name, MyIntRect texture_rect, AssetContext assets) : base()
        {
            this.sprite = new Sprite(assets.GetTexture(texture_name));

            this.sprite.TextureRect = texture_rect.AsSfmlIntRect();
            //this.sprite.Scale = new Vector2f(0.5f, 0.5f);
            //this.sprite.Rotation = (float)cAppMath.RadianToDegress(this.orientation);

            this.sprite.Origin = new Vector2f(texture_rect.Width / 2.0f, texture_rect.Height / 2.0f);
        }
Пример #5
0
        public cAnimatedSpriteRenderer(string sprite_id, MyIntRect view_offset_rect = null, bool repeat = false) : base()
        {
            AnimationInfo info = cAnimationAssets.Get(sprite_id);

            if (view_offset_rect != null)
            {
                info.ViewOffsetRect = view_offset_rect;
            }

            info.Repeat  = repeat;
            AnimationSrc = new cAnimation(info);
        }
Пример #6
0
        public void AddAnimState(cSpriteState state_type,
                                 Texture texture,
                                 int frame_width,
                                 int frame_height,
                                 int start_frame_column, //x
                                 int start_frame_row,    //y
                                 uint anim_start_frame,
                                 int num_frames,
                                 uint frame_time, // in ms
                                 MyIntRect view_rect,
                                 bool flip_vertically   = false,
                                 bool flip_horizontally = false)
        {
            if (view_rect.Width == 0 && view_rect.Height == 0)
            {
                view_rect.Width  = frame_width;
                view_rect.Height = frame_height;
            }

            cAnimation anim = new cAnimation(texture, view_rect);

            anim.AnimData.Repeat = true;

            anim.FlipHorizontally = flip_horizontally;
            anim.FlipVertically   = flip_vertically;
            //anim.SetSpriteSheet(texture);

            //float a_frame_width = texture.getSize().x / max_frames;
            //float a_frame_height = texture.getSize().y;

            for (int x = 0; x < num_frames; ++x)
            {
                anim.AddFrame(new MyIntRect((start_frame_column + x) * frame_width,
                                            start_frame_row * frame_height,
                                            frame_width,
                                            frame_height));
            }

            anim.SetFrameTime(frame_time);
            anim.SetStartFrame(anim_start_frame);

            //std::pair<SpriteState, cAnimation> state_pair = std::pair<SpriteState, cAnimation>(state_type, anim);

            m_SpriteStates.Add(state_type, anim);
        }
Пример #7
0
        public void RenderCentered(RenderTarget destination, Vector2f pos)
        {
            MyIntRect frame = this.GetCurrentFrame().DeepCopy();

            frame.Left += this.animData.ViewOffsetRect.Left;
            frame.Top  += this.animData.ViewOffsetRect.Top;

            frame.Width  = this.animData.ViewOffsetRect.Width;
            frame.Height = this.animData.ViewOffsetRect.Height;

            DrawingBase.DrawTextureUseCenter(destination,
                                             pos,
                                             this.GetTexture(),
                                             frame,
                                             Color.White,
                                             0.0f,
                                             1.0f,  //SCALE_FACTOR,
                                             false, //p_myCurrentAnim->IsFlippedHorizontally(),
                                             false,
                                             BlendMode.Add,
                                             null);
        }
Пример #8
0
        public static void DrawTextureSimple(RenderTarget destination,
                                             Vector2f location,
                                             Texture texture,
                                             MyIntRect sub_rect,
                                             Color coloration,
                                             BlendMode blend_mode
                                             )
        {
            Transform translationT = Transform.Identity;

            translationT.Translate(location);

            //Setup the render state.
            float left   = sub_rect.Left;
            float right  = left + sub_rect.Width;
            float top    = sub_rect.Top;
            float bottom = top + sub_rect.Height;

            float widthBeforeTransform  = sub_rect.Width;
            float heightBeforeTransform = sub_rect.Height;

            RenderStates states = new RenderStates(blend_mode, translationT, texture, null);


            //Setup the vertices and their attributes.

            VertexArray vertices = new VertexArray(PrimitiveType.Quads);


            vertices.Append(new Vertex(new Vector2f(0.0f, 0.0f), coloration, new Vector2f(left, top)));
            vertices.Append(new Vertex(new Vector2f(widthBeforeTransform, 0), coloration, new Vector2f(right, top)));
            vertices.Append(new Vertex(new Vector2f(widthBeforeTransform, heightBeforeTransform), coloration, new Vector2f(right, bottom)));
            vertices.Append(new Vertex(new Vector2f(0, heightBeforeTransform), coloration, new Vector2f(left, bottom)));



            destination.Draw(vertices, states);
        }
Пример #9
0
        protected override void initSprites()
        {
            base.initSprites();

            MyIntRect viewRect = Constants.CHAR_VIEW_RECT;

            spriteControl.AddAnimState(new cSpriteState(MotionType.STAND, HorizontalFacing.FACING_LEFT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       0,
                                       0,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.STAND, HorizontalFacing.FACING_RIGHT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       0,
                                       1,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.WALK, HorizontalFacing.FACING_LEFT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       0,
                                       0,
                                       0,
                                       3,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.WALK, HorizontalFacing.FACING_RIGHT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       0,
                                       1,
                                       0,
                                       3,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.JUMP, HorizontalFacing.FACING_LEFT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       1,
                                       0,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.JUMP, HorizontalFacing.FACING_RIGHT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       1,
                                       1,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);


            spriteControl.AddAnimState(new cSpriteState(MotionType.FALL, HorizontalFacing.FACING_LEFT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       6,
                                       0,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.FALL, HorizontalFacing.FACING_RIGHT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       6,
                                       1,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.LIE, HorizontalFacing.FACING_LEFT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       9,
                                       0,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);

            spriteControl.AddAnimState(new cSpriteState(MotionType.LIE, HorizontalFacing.FACING_RIGHT),
                                       Scene.Assets.GetTexture(Constants.MONSTER_TEXTURE_NAME),
                                       Constants.CHAR_FRAME_WIDTH,
                                       Constants.CHAR_FRAME_HEIGHT,
                                       9,
                                       1,
                                       0,
                                       1,
                                       FRAME_TIME,
                                       viewRect);
        }
Пример #10
0
        public static void DrawTexture(RenderTarget destination,
                                       Vector2f location,
                                       Texture texture,
                                       MyIntRect sub_rect,
                                       Color coloration,
                                       float rotation,
                                       float scale,
                                       bool flip_horizontally,
                                       bool flip_vertically,
                                       BlendMode blend_mode,
                                       Shader shader)
        {
            if (sub_rect.Width == 0 || sub_rect.Height == 0)
            {
                sub_rect.Top    = 0;
                sub_rect.Left   = 0;
                sub_rect.Width  = (int)texture.Size.X;
                sub_rect.Height = (int)texture.Size.Y;
            }

            //Set the position in space.
            Transform translationT = Transform.Identity;

            translationT.Translate(location);

            //Set the rotation (rotated around the center, since this Transform wasn't moved).
            Transform rotationT = Transform.Identity;

            rotationT.Rotate(rotation);

            Transform scaleT = Transform.Identity;

            scaleT.Scale(scale, scale);

            //Setup the render state.
            float left   = sub_rect.Left;
            float right  = left + sub_rect.Width;
            float top    = sub_rect.Top;
            float bottom = top + sub_rect.Height;

            float widthBeforeTransform  = sub_rect.Width;
            float heightBeforeTransform = sub_rect.Height;

            RenderStates states = new RenderStates(blend_mode, translationT * rotationT * scaleT, texture, shader);



            //Setup the vertices and their attributes.

            VertexArray vertices = new VertexArray(PrimitiveType.Quads);

            /*
             * Vertex vtx = vertices[0];
             * vtx.Position = new Vector2f(0, 0);
             * vtx.Color = coloration;
             * vtx.TexCoords = new Vector2f(left, top);
             * vertices[0] = vtx;
             *
             * vtx = vertices[1];
             * vtx.Position = new Vector2f(0, heightBeforeTransform);
             * vtx.Color = coloration;
             * vtx.TexCoords = new Vector2f(left, bottom);
             * vertices[1] = vtx;
             *
             * vtx = vertices[2];
             * vtx.Position = new Vector2f(widthBeforeTransform, heightBeforeTransform);
             * vtx.Color = coloration;
             * vtx.TexCoords = new Vector2f(right, bottom);
             * vertices[2] = vtx;
             *
             * vtx = vertices[3];
             * vtx.Position = new Vector2f(widthBeforeTransform, 0);
             * vtx.Color = coloration;
             * vtx.TexCoords = new Vector2f(right, top);
             * vertices[3] = vtx;
             */

            if (flip_vertically)
            {
                Utils.Swap <float>(ref top, ref bottom);
            }

            if (flip_horizontally)
            {
                Utils.Swap <float>(ref right, ref left);
            }

            vertices.Append(new Vertex(new Vector2f(0.0f, 0.0f), coloration, new Vector2f(left, top)));
            vertices.Append(new Vertex(new Vector2f(widthBeforeTransform, 0), coloration, new Vector2f(right, top)));
            vertices.Append(new Vertex(new Vector2f(widthBeforeTransform, heightBeforeTransform), coloration, new Vector2f(right, bottom)));
            vertices.Append(new Vertex(new Vector2f(0, heightBeforeTransform), coloration, new Vector2f(left, bottom)));



            //The transparency:

            /*
             * vertices[0].Color = coloration;
             * vertices[1].Color = coloration;
             * vertices[2].Color = coloration;
             * vertices[3].Color = coloration;
             *
             * //The pre-transform position and size:
             *
             *
             * vertices[0].Position = new Vector2f(0, 0);
             * vertices[1].Position = new Vector2f(0, heightBeforeTransform);
             * vertices[2].Position = new Vector2f(widthBeforeTransform, heightBeforeTransform);
             * vertices[3].Position = new Vector2f(widthBeforeTransform, 0);
             *
             * //Calculate the texture coordinates:
             *
             *
             * //If we're mirroring, swap the texture coordinates vertically and/or horizontally.
             * /*
             * if (flip_vertically) std::swap(top, bottom);
             * if (flip_horizontally) std::swap(left, right);
             */

            //Set the texture coordinates:

            /*
             * vertices[0].TexCoords = new Vector2f(left, top);
             * vertices[1].TexCoords = new Vector2f(left, bottom);
             * vertices[2].TexCoords = new Vector2f(right, bottom);
             * vertices[3].TexCoords = new Vector2f(right, top);
             */
            //Use the RenderTarget to draw the vertices using the RenderStates we set up.

            destination.Draw(vertices, states);

            //vertices.Draw(destination, states);
        }
Пример #11
0
        public static void DrawTextureUseCenter(RenderTarget destination,
                                                Vector2f location,
                                                Texture texture,
                                                MyIntRect sub_rect,
                                                Color coloration,
                                                float rotation,
                                                float scale,
                                                bool flip_horizontally,
                                                bool flip_vertically,
                                                BlendMode blend_mode,
                                                Shader shader)
        {
            if (sub_rect.Width == 0 || sub_rect.Height == 0)
            {
                sub_rect.Top    = 0;
                sub_rect.Left   = 0;
                sub_rect.Width  = (int)texture.Size.X;
                sub_rect.Height = (int)texture.Size.Y;
            }


            //Set the position in space.
            Transform translationT = Transform.Identity;

            translationT.Translate(location); //location

            //Set the rotation (rotated around the center, since this Transform wasn't moved).
            Transform rotationT = Transform.Identity;

            rotationT.Rotate(rotation);

            Transform scaleT = Transform.Identity;

            scaleT.Scale(scale, scale);

            //Setup the render state.
            float left   = sub_rect.Left;
            float right  = left + sub_rect.Width;
            float top    = sub_rect.Top;
            float bottom = top + sub_rect.Height;

            float widthBeforeTransform  = sub_rect.Width;
            float heightBeforeTransform = sub_rect.Height;

            RenderStates states = new RenderStates(blend_mode, translationT * rotationT * scaleT, texture, shader);



            //Setup the vertices and their attributes.

            VertexArray vertices = new VertexArray(PrimitiveType.Quads);


            if (flip_vertically)
            {
                Utils.Swap <float>(ref top, ref bottom);
            }

            if (flip_horizontally)
            {
                Utils.Swap <float>(ref right, ref left);
            }

            // centered

            vertices.Append(new Vertex(new Vector2f(-widthBeforeTransform / 2, -heightBeforeTransform / 2), coloration, new Vector2f(left, top)));
            vertices.Append(new Vertex(new Vector2f(widthBeforeTransform / 2, -heightBeforeTransform / 2), coloration, new Vector2f(right, top)));
            vertices.Append(new Vertex(new Vector2f(widthBeforeTransform / 2, heightBeforeTransform / 2), coloration, new Vector2f(right, bottom)));
            vertices.Append(new Vertex(new Vector2f(-widthBeforeTransform / 2, heightBeforeTransform / 2), coloration, new Vector2f(left, bottom)));

            /*
             * vertices.Append(new Vertex(new Vector2f(0.0f, 0.0f), coloration, new Vector2f(left, top)));
             * vertices.Append(new Vertex(new Vector2f(widthBeforeTransform, 0), coloration, new Vector2f(right, top)));
             * vertices.Append(new Vertex(new Vector2f(widthBeforeTransform, heightBeforeTransform), coloration, new Vector2f(right, bottom)));
             * vertices.Append(new Vertex(new Vector2f(0, heightBeforeTransform), coloration, new Vector2f(left, bottom)));
             */
            //Use the RenderTarget to draw the vertices using the RenderStates we set up.

            destination.Draw(vertices, states);
        }
Пример #12
0
 public cAnimation(Texture sprite_sheet, MyIntRect view_offset_rect)
 {
     animData = new AnimationInfo(sprite_sheet, new List <MyIntRect>(), view_offset_rect);
     init();
 }
Пример #13
0
 public void AddFrame(MyIntRect rect)
 {
     this.animData.Frames.Add(rect);
 }