示例#1
0
        //!Need to add better support for custom styles
        public void RenderGameEntity(GameEntity gent, View view)
        {
            HtmlElement gentlement = null;
            if (elementsByGameObjectId.ContainsKey(gent.GetId()))
            {
                gentlement = elementsByGameObjectId[gent.GetId()].As<HtmlElement>();
            }

            //if it's not rendered, render it
            if (gentlement == null)
            {
                gentlement = document.createElement("div").As<HtmlElement>();
                gentlement.id = gent.GetId();
                //later, we may want to add iterating through base types to get their type name and add it...
                this.AddClass(gentlement, "Entity");
                this.AddClass(gentlement, gent.GetType().Name);
                document.getElementById("gameBoard").appendChild(gentlement);
                foreach (string style in gent.GetCustomStyles())
                {
                    this.AddClass(gentlement, style);
                }
                if (gent.GetSprite() != null && gent.GetSprite().ScaleToSize == true)
                {
                    gentlement.style.backgroundSize = gent.GetSprite().Size.width + "px " + gent.GetSprite().Size.height + "px ";
                }

                elementsByGameObjectId[gent.GetId()] = gentlement;
            }

            if (gent.GetTypeName() == "Tile")
            {
                tilesRendrin++;
                Color tileCol = gent.As<Tile>().GetLightLevel();
                gentlement.style.backgroundColor = "rgb(" + tileCol.red + ", " + tileCol.green + ", " + tileCol.blue + ");";
                if (gent.GetSize().width != Stage.CurrentStage.GetTileSize().width || gent.GetSize().height != Stage.CurrentStage.GetTileSize().height)
                {
                    gentlement.style.width = Stage.CurrentStage.GetTileSize().width + "px";
                    gentlement.style.height = Stage.CurrentStage.GetTileSize().height + "px";
                }
            }

            if(this.gameEntitiesToUpdate.Contains(gent.GetId()))
            {
                //reposition the element based on game position
                gentlement.style.left = (gent.GetPosition().x * Stage.CurrentStage.GetTileSize().width) + "px";
                gentlement.style.top = ((Stage.CurrentStage.Height - gent.GetPosition().y - gent.Height)
                    * Stage.CurrentStage.GetTileSize().height) + "px";
                gentlement.style.opacity = gent.GetOpacity().ToString();

                this.gameEntitiesToUpdate.Remove(gent.GetId());
            }

            //if the entity doesn't have a sprite, we're done with all rendering for now
            if (gent.GetSprite() == null)
            {
                gentlement.style.border = "1px dashed blue";
                return;
            }

            //call the sprite's animate function
            //it will return the id of the frame that the sprite and its animation are currently on
            string frameId = gent.GetSprite().Animate();
            Debug.Watch("Animation count", gent.GetSprite().GetCurrentAnimation().animationCount.ToString(), true);

            //if that result is different from the value we have stored as this GameEntity's current display frame,
            if (frameId != gent.GetSprite().CurrentRenderFrame)
            {
                //update this thing's CSS to the new frame
                //jQueryObject GameEntityDiv = jQuery.FromElement(GameEntityDiv);
                this.RemoveClass(gentlement, gent.GetSprite().CurrentRenderFrame);
                this.AddClass(gentlement, frameId);
                derp = gentlement.className;
                //and update our current frameid
                gent.GetSprite().CurrentRenderFrame = frameId;

                gentlement.style.width = gent.GetSprite().Size.width + "px";
                gentlement.style.height = gent.GetSprite().Size.height + "px";
            }
        }
示例#2
0
 public void SetNeedsUpdate(GameEntity gent)
 {
     if (!this.gameEntitiesToUpdate.Contains(gent.GetId()))
     {
         this.gameEntitiesToUpdate.Add(gent.GetId());
     }
 }
示例#3
0
 public void DestroyGameEntity(GameEntity gent)
 {
     Element gentlement = elementsByGameObjectId[gent.GetId()];
     if (gentlement != null)
     {
         try
         {
             gentlement.parentElement.removeChild(gentlement);
             elementsByGameObjectId.Remove(gent.GetId());
         }
         catch (Exception ex)
         {
             Debug.log("Failed to destroy " + gent.GetId() + " ( " + gent.GetName() + " ) :");
             Debug.log(ex.Message);
         }
     }
 }