Hello Guest

Author Topic: Vanishing image in Graphics<> list  (Read 2741 times)

0 Members and 1 Guest are viewing this topic.

Fatesauce

  • Member
  • Posts: 26
    • View Profile
Vanishing image in Graphics<> list
« on: July 05, 2015, 12:35:05 AM »
Heres the problem code from a class inheriting from Entities.

Code: [Select]
private void drawImage()
        {

            Image topLeft = new Image(BUTTON_GRAPHIC);
            Image topRight = new Image(BUTTON_GRAPHIC);
            Image botRight = new Image(BUTTON_GRAPHIC);
            Image botLeft = new Image(BUTTON_GRAPHIC);

            topRight.FlippedX = true;
            botRight.FlippedX = true;
            botRight.FlippedY = true;
            botLeft.FlippedY = true;

            topLeft.X = 0;
            topLeft.Y = 0;
            topRight.X = btnSizeX - 8;
            topRight.Y = 0;
            botLeft.X = 0;
            botLeft.Y = btnSizeY - 8;
            botRight.X = btnSizeX - 8;
            botRight.Y = btnSizeY - 8;

            Graphics.Add(topLeft);
            Graphics.Add(topRight);
            Graphics.Add(botLeft);
            Graphics.Add(botRight);
        }

Basically it draws the 4 corners of a button widget.  Or its supposed to.  When I go to test it, the first image (topLeft) appears for about 5 seconds then vanishes, leaving me with only 3 images displayed.  If I add a second instance of the first image like this:

Code: [Select]
private void drawImage()
        {
            Image topLeftDummy = new Image(BUTTON_GRAPHIC);
            Image topLeft = new Image(BUTTON_GRAPHIC);
            Image topRight = new Image(BUTTON_GRAPHIC);
            Image botRight = new Image(BUTTON_GRAPHIC);
            Image botLeft = new Image(BUTTON_GRAPHIC);

            topRight.FlippedX = true;
            botRight.FlippedX = true;
            botRight.FlippedY = true;
            botLeft.FlippedY = true;

            topLeft.X = 0;
            topLeft.Y = 0;
            topRight.X = btnSizeX - 8;
            topRight.Y = 0;
            botLeft.X = 0;
            botLeft.Y = btnSizeY - 8;
            botRight.X = btnSizeX - 8;
            botRight.Y = btnSizeY - 8;

            Graphics.Add(topLeftDummy);
            Graphics.Add(topLeft);
            Graphics.Add(topRight);
            Graphics.Add(botLeft);
            Graphics.Add(botRight);
        }

Then it works fine and I have all 4 corners.  I want to say its something to do with the 0 index in the Entities.Graphics list but i dont think its the case because I havent come across this issue before. 

Its ONLY the first image that vanishes.  Bug, or user error?

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Vanishing image in Graphics<> list
« Reply #1 on: July 06, 2015, 11:49:06 PM »
Hmmm well I don't have any initial thoughts on why this is happening.  If it's after about 5 seconds... is there anything else going on in your code that changes something at 5 seconds?  I haven't seen any bugs with multiple graphics like this but I'll do some tests on my end to see if I can reproduce it.

Are you calling DrawImage only once?

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Vanishing image in Graphics<> list
« Reply #2 on: July 06, 2015, 11:56:45 PM »
I'm doing a quick test with an Entity:

Code: [Select]
    class GraphicTest : Entity {

        public GraphicTest(float x, float y, string source) : base(x, y) {
            var imgTopLeft = new Image(source);
            var imgTopRight = new Image(source);
            var imgBottomLeft = new Image(source);
            var imgBottomRight = new Image(source);

            imgTopLeft.Scale = 0.2f;
            imgTopRight.Scale = 0.2f;
            imgBottomLeft.Scale = 0.2f;
            imgBottomRight.Scale = 0.2f;

            imgTopRight.SetPosition(100, 0);
            imgBottomLeft.SetPosition(0, 100);
            imgBottomRight.SetPosition(100, 100);

            imgTopRight.FlippedX = true;
            imgBottomLeft.FlippedY = true;
            imgBottomRight.FlippedX = imgBottomRight.FlippedY = true;

            AddGraphics(imgTopLeft, imgTopRight, imgBottomLeft, imgBottomRight);
        }

        public override void Update() {
            base.Update();

            SetPosition(Scene.MouseX, Scene.MouseY);
        }
    }

And all the images are working fine for me -- no vanishing graphics.  There might be something else going on in your code that is removing the graphic at position 0.  (using the "Graphic" property on an Entity does return Graphics[0], so I wonder if you're manipulating that somewhere?)

Fatesauce

  • Member
  • Posts: 26
    • View Profile
Re: Vanishing image in Graphics<> list
« Reply #3 on: July 07, 2015, 12:40:46 PM »
Nothing else I can think of.  Draw Image is only called once when the scene is created.  The program consists of the button and thats it.  Its got me stumped as well because Ive used the Graphics list for a few other things and never had a problem. At all.  There is nothing in my code that works on any kind of timer or anything to prompt a change after a certain time.

Ill modify the code to make use of the functions you used, which I didnt, to see if it makes a change.

The graphic im using is just a wee 8px by 8px png

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Vanishing image in Graphics<> list
« Reply #4 on: July 07, 2015, 02:20:48 PM »
Are you able to create a project that contains the bare minimum required to reproduce the issue?

Fatesauce

  • Member
  • Posts: 26
    • View Profile
Re: Vanishing image in Graphics<> list
« Reply #5 on: July 08, 2015, 07:43:15 PM »
Ok so heres the code. Works perfect. Ill have to sift through my other crap to see where the conflict is.  Ill keep you posted.  Unless you want the project folder of the issue causing program.  Its not exactly top secret lol

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Otter;

namespace DebugTestImage
{
    class Program
    {
        static void Main(string[] args)
        {

            Game game = new Game();
            game.FirstScene = new TestScene();
            game.Start();

        }
    }

    class TestScene : Scene
    {

        public TestScene()
        {
            Add(new TestButton());
        }
       
    }

    class TestButton : Entity
    {

        private const string BUTTON_GRAPHIC = ("../../Assets/Graphics/UI/button.png");

        public TestButton()
        {
            Image topLeft = new Image(BUTTON_GRAPHIC);
            Image topRight = new Image(BUTTON_GRAPHIC);
            Image botRight = new Image(BUTTON_GRAPHIC);
            Image botLeft = new Image(BUTTON_GRAPHIC);

            topRight.FlippedX = true;
            botRight.FlippedX = true;
            botRight.FlippedY = true;
            botLeft.FlippedY = true;

            topRight.SetPosition(50, 0);
            botLeft.SetPosition(0, 50);
            botRight.SetPosition(50, 50);

            AddGraphics(topLeft, topRight, botLeft, botRight);
        }
    }
}