Exemple #1
0
        //----------------------------------------------------------------------------------------
        public void setFrame(Entity e, int frameNum)
        {
            DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME);

            if (frameNum < drawComp.getSprite().getNumImages())
            {
                drawComp.getSprite().currentImageIndex = frameNum;
            }
            else
            {
                Console.WriteLine("Trying to change " + e + " sprite to nonexistant frame: " + frameNum);
            }
        }
Exemple #2
0
        public void refreshImage(bool left)
        {
            DrawComponent drawComp = ( DrawComponent )this.getComponent(GlobalVars.DRAW_COMPONENT_NAME);

            int spriteNum = drawComp.getSprite().currentImageIndex;

            if (left)
            {
                drawComp.setSprite(activeLeftImage);
            }
            else
            {
                drawComp.setSprite(activeRightImage);
            }

            drawComp.getSprite().currentImageIndex = spriteNum;
        }
Exemple #3
0
        public void stopAnimation()
        {
            AnimationComponent animComp = ( AnimationComponent )this.getComponent(GlobalVars.ANIMATION_COMPONENT_NAME);

            if (animComp.animationOn)
            {
                animComp.animationOn = false;
                DrawComponent drawComp = ( DrawComponent )this.getComponent(GlobalVars.DRAW_COMPONENT_NAME);
                if (forceLargeStopImage && (drawComp.getSprite().currentImageIndex == 0 || drawComp.getSprite().currentImageIndex == 2))
                {
                    drawComp.getSprite().currentImageIndex++;
                }
                else if (forceSmallStopImage)
                {
                    drawComp.getSprite().currentImageIndex = 0;
                }
            }
        }
Exemple #4
0
        //You must have an Update.
        //Always read in deltaTime, and only deltaTime (it's the time that's passed since the last frame)
        //Use deltaTime for things like changing velocity or changing position from velocity
        //This is where you do anything that you want to happen every frame.
        //There is a chance that your system won't need to do anything in update. Still have it.
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                AnimationComponent animComp = ( AnimationComponent )e.getComponent(GlobalVars.ANIMATION_COMPONENT_NAME);
                DrawComponent      drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME);

                if (animComp.animationOn)
                {
                    animComp.timeUntilNextFrame -= deltaTime;

                    if (animComp.timeUntilNextFrame <= 0)
                    {
                        drawComp.getSprite().currentImageIndex++;
                        if (drawComp.getSprite().currentImageIndex >= drawComp.getSprite().getNumImages())
                        {
                            drawComp.getSprite().currentImageIndex = 0;
                            if (animComp.pauseIndefinitelyAfterCycle)
                            {
                                animComp.animationOn = false;
                                if (animComp.imageAfterCycleName != null)
                                {
                                    drawComp.setSprite(animComp.imageAfterCycleName);
                                }
                                drawComp.getSprite().currentImageIndex = 0;
                            }
                            if (animComp.destroyAfterCycle)
                            {
                                level.removeEntity(e);
                                continue;
                            }
                            animComp.timeUntilNextFrame = animComp.animationFrameTime + animComp.pauseTimeAfterCycle;
                            drawComp.getSprite().currentImageIndex = 0;
                        }
                        else
                        {
                            animComp.timeUntilNextFrame = animComp.animationFrameTime;
                        }
                    }
                }
            }
        }