Example #1
0
        public sprite(Vector2 position_0, Vector2 velocity_0, texture texture_0, Vector2?size_0 = null, float zLevel = 0)
        {
            center        = position_0;
            velocity      = velocity_0;
            texture       = texture_0;
            z             = zLevel;
            frameDuration = 0;// since we won't have animation -- it is not animated
            if (size_0 == null)
            {
                //if size_0 is not overriden, use texture size
                size = texture.size;
            }

            updateVertices();
        }
Example #2
0
        public static texture[] LoadTexture(string spritePath, bool transparentColor, Color alphaChan, int stripFrames)
        {
            List <texture> cache = new List <texture>();
            texture        t     = new texture();
            string         path  = spritePath;

            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException(path);
            }

            System.Drawing.Imaging.PixelFormat pixelForm;
            if (IsLinux)
            {
                pixelForm = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
            }
            else
            {
                pixelForm = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
            }

            for (int animationFrame = 0; animationFrame < stripFrames; animationFrame++)
            {
                GL.End();
                int id = GL.GenTexture();
                t.id = id;
                GL.BindTexture(TextureTarget.Texture2D, id);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                using (Bitmap BMP = new Bitmap(path))
                {
                    if (transparentColor)
                    {
                        BMP.MakeTransparent(alphaChan);
                    }
                    t.size = new Vector2(BMP.Width / stripFrames * Globals.Width, BMP.Height * Globals.Height);
                    BitmapData bmpData = BMP.LockBits(new Rectangle(0 + animationFrame * (BMP.Width / stripFrames), 0, BMP.Width / stripFrames, BMP.Height), ImageLockMode.ReadOnly, pixelForm);
                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmpData.Width, bmpData.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0);
                    BMP.UnlockBits(bmpData);
                }
                GL.Disable(EnableCap.Texture2D);
                cache.Add(t);
            }

            return(cache.ToArray());
        }
Example #3
0
        public override void update(double time)
        {
            this.center.X += this.velocity.X * (float)time; // 60.0f;
            this.center.Y += this.velocity.Y * (float)time; // 60.0f;

            if (frameDuration > 0)                          // then it is animated
            {
                frameTime += (float)time;
                if (frameTime >= frameDuration)
                {
                    frameTime       = 0;
                    animationFrame += 1;
                    if (animationFrame > textures.Length - 1)
                    {
                        animationFrame = 0;
                    }
                    texture = textures[animationFrame];
                }
            }

            updateVertices();
        }