Jump to content
  • Advertisement

Jakob Krarup

  • Content Count

  • Joined

  • Last visited

Community Reputation

159 Neutral

About Jakob Krarup

  • Rank

Personal Information

  1. Jakob Krarup

    spriteBatch.Draw slow?

    Do you only have a single SpriteBatch.Begin before and a single SpriteBatch.End after your drawing? Having many separate spritebatches with the begin/end will slow your drawing down a lot.
  2. Jakob Krarup

    2D tilemaps "Chunk Theory".

    Hi Shippou You could fiddle a bit with the chunk sizes, to ensure that you would only read/dump files from and to disk every so often. If your maps are pretty simple, the amount of data in memory shouldn't be a problem. To my knowledge this is the same way Minecraft does it. You could also cache a bigger amount of chunks, say two concentric circles worth around the one the player is currently in. I can't see this becoming a problem on modern computers. Try the sample that's for download on my Blog - I haven't experienced any problems, and the chunks there are very small, to illustrate the concept. If you make 255x255 chunks you would load a lot less and the files would still be fast to read and not too much of a strain on memory. Kind regards - Jakob
  3. Jakob Krarup

    2D tilemaps "Chunk Theory".

    Hi Mellkor A similar question popped up on the Microsoft XNA forums a while back, and I posted some graphics to visualize the theory and a code sample with class diagram. (scroll down to "I found some time yesterday, and coded a framework for making infinite worlds.")   I hope it will prove useful to you    Kind regards - Jakob
  4. Jakob Krarup

    Critique for first game

    Yup - they are now :) Nice game! The gfx for the menu and introscreen is very nice. I like the concept, but I don't get the feeling that what I do changes very much in the game. If I move in a different direction all the small enemies quickly catch up to me, and the big enemy is very hard to outmaneuver. I would like small explosions as well when I hit or when I am hit, so I get the reward (feedback) for aiming well. A little sound for each shot being fired would be nice too.   Overall a very good first game! :)   Kind regards - Jakob
  5. Jakob Krarup

    Rotate sprites around a point in 2D

    Glad to hear it! :) Cudos on coming back with your solution for future reference :)   /Jake
  6. Jakob Krarup

    Critique for first game

    The links are down. Maybe it has to do with DropBox having trouble, but otherwise, if you could upload again? :)
  7. Jakob Krarup

    Rotate sprites around a point in 2D

    Hi Dobbydoo It sounds like there are two different tasks here:   1) Getting the mouse's position relative to the parent object (where you want the childobject attached, right?). 2) Drawing the child object in-game while being able to rotate its position and Texture.     Solving 1 is pretty simple:   To get direction from object to mouse as a Vector2, subtract object's position (a Vector2) from mouse's position (also a Vector2):   Vector2 distanceAndDirectionFromObjectToMouse = mousePosition - objectPosition;   This value you can store along with the child object, to know where to draw it in relation to the parent.   Solving 2) is more complicated. You want to be able to rotate the child object's position around the parent. To do this you need to: Find the current rotation of and distance to the child object change the rotation by the wanted amount calculate the new position using cos and sin (you may want to read up on these) basically cos(angle) gives you the X coordinate of where to position something, and sin(angle) gives you the Y coordinate. Getting the rotation of a Vector2 is possible using the Atan2 function:   private float Vector2ToRadian(Vector2 direction) {     return (float)Math.Atan2(direction.X, -direction.Y); }   Radian is  a type of measurement where there are 2 * PI degrees (approximately 6.283) around the full circumference of the circle as opposed to regular degrees where you have 360.   Getting the distance is a method on the Vector2 struct called Length().   float distanceToChild = distanceAndDirectionFromObjectToMouse.Length();   using the distance and rotation you can use the following method to find the new location of the child object (the "sattelite" in the methodname below):   public Vector2 GetPositionOfSatellite(Vector2 center, float distance, float directionInRadians)   {           float yDifference = (float)Math.Sin(directionInRadians);           float xDifference = (float)Math.Cos(directionInRadians);           Vector2 direction = new Vector2(xDifference, yDifference);           Vector2 precisePositionOfSatellite = center + direction * distance;           return precisePositionOfSatellite;       }    If that is unclear, you may benefit from the two articles I've taken code from:   http://xnafan.net/2012/12/pointing-and-moving-towards-a-target-in-xna-2d/ http://xboxforums.create.msdn.com/forums/p/112011/670251.aspx#670251   ...otherwise, just ask   Kind regards - Jakob
  8. Jakob Krarup

    XNA - Tile Engine With Collision

    Hi :)   Here you can download codesamples for reading a map from a textfile. http://xnafan.net/2013/01/2d-map-generation-for-xna/   This code uses numeric values, but you can change what you do with the characters read to a SWITCH statement like you are mentioning in your question.   Kind regards - Jakob
  9. Jakob Krarup

    Loading sprites (big map) XNA

    Here's a code framework for infinite worlds implemented in XNA: http://xboxforums.create.msdn.com/forums/p/111091/664227.aspx#664227   You would have to make an implementation of IPermanentMapStorage which gets maps from a webservice.  You can probably use the rest of the code as is   /Jake   P.S. in case you are interested in seeing the newest version, which uses Perlin noise for map generation (not a requirement for the framework), it is attached to this post.
  10. Jakob Krarup

    Static Creations and upcoming XNA Game

    Cool :)   Good luck!   /Jake
  11. Jakob Krarup

    Problem displaying correct portion of a scene

    Hi tmccolgan88     What you need is a "camera". And I put "camera" in quotation marks, because it is merely a way of thinking about the concept. Whenever you are drawing the background, you are using the absolute coordinates, which makes them stay where they are, and your player move, as you point out. What you are looking for is a way to "translate the coordinates of the world into the screen, based on the player's position". This can be done by storing a Vector2 (yes - you may call it "_camera", to keep up the illusion that there *is* a real camera ;)), and updating the value of that vector based on the player's movements. Whenever you want to draw the background (world), you subtract the position of the camera from the position of the tiles/map-pieces/whatever, to make it the new origin for coordinates (it will be the top-left corner of the screen).   Does that make sense?  Otherwise Google "2D camera" or ask again   Kind regards - Jakob
  12. Jakob Krarup

    Setting coordinates in map editor

    Hi Burnt_casadilla   You can change the line:   builder.Append(separator + (map[x, y] > oceanLevel ? "X" : " ")); to   builder.Append(separator + map[x, y]);     This will look up the value in the double array at position x,y and add that to the StringBuilders buffer for later retrieval. EDIT: I added an extended version of the editor to the blogpost (at the bottom), which supports saving the heightmap (and you can look at the code for loading from the file as well, though the application doesn't support it).   as for adding a border - you can do this with a for-loop, iterating through zero to max on both the Y and X axis, and setting the value there to 50 if either the X or the Y value is either zero or max.   If that doesn't make sense, ask again   Kind regards - Jakob Krarup ;-)
  13. Jakob Krarup

    Help with Worm Clone Draw() method

    Hi Manhattanisgr8 :)    I am currently making a tutorial on how to code a snake game in XNA, so you're welcome to have my code so far to look at for inspiration. I've chosen the List<Point> implementation, and then just drawing the List[0] part as a different texture to show the head.   Here's the code, and here's a screendump of the game so far:     Let me know if any of it gives you any trouble :)   Kind regards - Jakob
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!