• Content count

  • Joined

  • Last visited

Community Reputation

116 Neutral

About MrZeo

  • Rank
  1. Help with Worm Clone Draw() method

    Its hard to tell, maybe you are incorrectly substracting 1 when looping through your body parts in draw?   for (int i = 0; i < wormBodyTexture.Count; i++)   Have you considered making a simple BodyPart class, and making a list of those that would represent the worm. First object in the list would be the head and last one the tail. When the worm moves you would just remove the last item from the list and insert new one at the start of the list based on direction you are going. When you eat something you just dont remove the last item and thus the worm gets larger. For collision you can easily check if the new head position collides with any other BodyPart in the list or walls of the map. When drawing you would just loop through the list, drawing the first part with head texture, last with tail, and the rest with body texture. Later on when you have the basics down you could easily expand the class to do all kinds of neat stuff. I hope that wasn't too confusing. :>
  2. Help with Worm Clone

    Vector2 is a struct and therefore a value type. When you return value from list you actually get a copy of the value instead of reference. That is why you can't modify the original value in list.   EDIT: This should work not sure if it is a good way to do it though:   var temp = wormBodyPosition[i]; temp.X += wormBodyWidth; wormBodyPosition[i] = temp;
  3. Reading array of Rectangles from XML

      Thank you, excactly the information I needed, the built in serializer isn't very well documented.   Now for example I'm deserializing class something like this: public class SomeDataList { [ContentSerializer] private SomeData[] data; // public properties and other stuff. public SomeDataList() {} public SomeData GetSomeData(int index) { // return stuff. } }   If I understood correctly the serializer requires parameterless constructor. Can I just mark this constructor private to only ever create instances of the class during content loading?   Also just to clarify I am correct on this right? // Both reference the same object. SomeDataList listFirst = Content.Load<SomeDataList>("ListOne"); SomeDataList listSecond = Content.Load<SomeDataList>("ListOne"); // Two different objects. SomeDataList listFirst = Content.Load<SomeDataList>("ListOne"); SomeDataList listSecond = Content.Load<SomeDataList>("ListTwo");   Thanks for the help again. :>
  4. I'm bit confused why do I have to format array of Rectangles like this: <SourceRect> 0 0 48 36 48 0 48 36 </SourceRect> ...instead of using <item></item> or <Rectangle></Rectangle> tags for each component in array?   I've been using the default method described here to load XML content in to the XNA project:
  5. Drawing large tile maps

    Thx for all the replies! I have to be able to interact with the map runtime so I don't think splitting it to textures would work. I was able to make some progress though. I dropped the whole idea of separate tile class and instead have the data in simple byte[x,y,z] array. I'm not really sure what was causing the slowdown before but now I can run steady 60 fps as long as I don't zoom too far out.   I probably have to change to SpriteSortMode.BackToFront so that I can utilize layerdepth for sorting. Even though I'm already naturally sorting the map itself, I have to somehow get depth sorted with moving objects that might be behind parts of the map.   Here is the draw/culling, not pretty but does the job:   public void Draw(SpriteBatch spriteBatch) { // Start tile of horizontal row to be drawn. int dx = topLeft.X; int dy = topLeft.Y; // Tile to be drawn. int x, y; bool swap = true; spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, camera.GetViewMatrix()); do { // Update tile to start coordinates of new row. x = dx; y = dy; do { // Make sure we are within map limits. if (x >= 0 && x < Map.X && y >= 0 && y < Map.Y) { for (int z = 0; z < Map.Z; z++) { if (data[x, y, z] > 0) { tilePosition = IsoTransform(x, y); GetTileData(data[x, y, z], z, ref sourceRect, ref tileAlpha); spriteBatch.Draw(tileSheet, tilePosition, sourceRect, tileColor * tileAlpha, 0, tileOrigin, 1f, SpriteEffects.None, 0); } } } // Add to draw our next horizontal tile. x++; y--; } while (x <= dx + maxX); // Horizontal row done. // Add to either dx or dy to get to the next row. if (swap) { dx += 1; swap = false; } else { dy += 1; swap = true; } } while (dy <= topLeft.Y + maxY); // We are done drawing once we reach maxY. spriteBatch.End(); }         private void UpdateLimits()         {             // Get view rect coordinates.             Vector2 topLeft = Vector2.Transform(new Vector2(0, 0), camera.InverseViewMatrix);             Vector2 bottomRight = Vector2.Transform(screenSize, camera.InverseViewMatrix);             // Calculate how many tiles fit in to this view.             maxX = (int)(bottomRight.X - topLeft.X) / Tile.X;             maxY = (int)(bottomRight.Y - topLeft.Y) / Tile.Y;             // Get first tile to be drawn.             this.topLeft = WorldToTile(topLeft, false);             // Add a bit extra around the view to make sure half tiles get drawn.             maxX += 3;             maxY += 3;             this.topLeft.X -= 2;         }  
  6. Drawing large tile maps

    Hello everyone!   I've been recently working on 2d isometric tile engine using XNA as school project. I've set up the engine to limit drawing only to what is inside the camera view. Problem is as soon as I start zooming out and therefore increasing the amount of tiles to be drawn the framerate starts to drop really fast. Around 100x100x3 (3 is the amount of layers for grass, roads etc) draw calls is enough to go from 60 to 50 FPS.   So how do other tile based games handle drawing large areas? For example I remember in OpenTTD you could zoom pretty far out and have huge maps (something like 2048x2048) yet it was really smooth. Thank you in advance for any solution/different approach you might have.   Also I'm new here, so hi again! I hope this is the right section for this topic.