I've been making a 2D game with XNA that will have several unique enemies. I have no trouble drawing separate sprites to the screen, one over the other to make no two enemies alike, but I think it might be more efficient if instead of drawing a dozen sprites per enemy, I somehow merged those sprites into one sprite sheet.
If I have lots and lots of these enemies on the screen, will I improve performance by a worthy amount if I do merge? And is there a simple way for me to create new sprite sheets in this way, or is the answer quite fiddly?
It can be faster to draw one sprite instead of several. However, I would only recommend this, if you have performance problems. Drawing sprites is quite fast with the SpriteBatch. It has the nice feature to group draw calls of the same texture, which makes it pretty fast. If you create a separate texture for each enemy, you can loose this feature, which could result in a performance loss. Creating one large sprite sheet can be better, if the sheet does not get too large.
To create such a sheet, you have to create a texture / render target and render to it. Here is how to do it with XNA.
Related
I have a really peculiar question. I want to deteriorate the graphics in Unity of just a part of the screen. For example, if I'm playing a game with the screen split in two, one player can be playing with ultra graphics and the other, low ones. Is there a simple way of doing this, like setting the graphics quality on each camera? Thank you so much for your help!
I don't imagine and easy way to do that.
Graphics are the conglomerate of multiple things (at least for me); the number of polygons of an object, the size of the textures, etc.
So the only thing I know you can do, is to duplicate the scene (like if you are making and on-line game) and load this duplicate scene with different materials, models and textures on one player scene. Then synchronize the rest of the scene, so both players are looking the "same" scene.
Also you can "deform" the image, with shaders or camera filters, like a Blurr effect! But this won't really affect the "graphics".
I don't think that's currently possible. The game would have to render the same objects on 2 different ways, but that's just not possible in a good-performance scenario. You could very simple use prefabs with a lower quality on one of the screens or images with a lower resolution in the UI.
Do you really need this for your game? If u do some changes in the quality settings or change your game core mechanics, maybe the performance becomes good enough to skip this.
Im developing a game like "bubble-bobble". So far I have done physics and collision detection.
Now I want to make my Hero (Rectangle Sprite) animated. I would be glad if someone could explain simple scripting for simple animated characters or some nice links for animation.
The XNA Documentation includes an entire article on Animating a Sprite. The basic technique is to use an AnimatedTexture class, which is included within the Animated sprite sample code.
The high level idea is that you load a texture into memory using a graphics API. Since you're using C#, this is most likely done through XNA.
This texture you have loaded contains each frame of animation that is required, and may span across multiple textures. When you go and render your 'sprite' object, you pass the XNA API the texture you want to use, and a source rectangle coordinates that surround the specific frame of animation you want within that texture.
It's up to you to manage this process. I create tools that assemble these source rectangles and stores meta data about each specific animation each sprite has; like which rectangles, and the duration of each frame, etc.
I'm planning to draw these shapes in WPF. It's for an educational software.
What idea's do you have in how to implement these cubes and views?
I was planning at the beginning starting using canvas and draw, but I guess it will be become eternal. So I supposed if exists some library to help me drawing them?
The ability to draw 3D shapes (such as cubes) and render them from different angles is built right into WPF. From the look of your cubes, you're going to want an orthographic camera, rather than a perspective camera, because the lines composing your cubes are parallel.
You might also find the Petzold.Media3D library helpful, because it has objects like cubes built in (you don't have to write your own algorithms to build them).
Finally, you might this primer helpful in getting started with WPF 3D.
Once you have some idea of how to use 3D, it will just be a matter of putting cubes in your scene at the proper locations and positioning the cameras properly for viewing the cubes. You will probably want to keep reusing the same four camera positions: one for the "3D view", and one each for the top, side, and front views.
This should be a lot less work than trying to draw the cubes using 2D.
For our game we have to create collision detection.
The problem is that the collided objects are in different canvasses/layers, which makes collision detection by pointlocation inpossible.
Does anyone have an idea how to solve this?
It's hard to give a great answer without some more information, but if all your layers are the same size then you can just roll your own collision detection. All you need to know is the locations and sizes of two things to be collision detected. Then you just test to see if one rectangle intersects with the other rectangle.
There is also a function that might be useful to use called TranslatePoint. This translates from one UIElements coordinates to another. So if you had a ball bouncing around in a smaller area of the screen with it's own local coordinate system, you could get the ball's coordinates relative to the entire screen with this function.
Can I suggest you try using the Farseer physics engine just to save yourself some pain?
http://farseerphysics.codeplex.com/
It's very good and is in use in some WP7 games already.
http://www.farseergames.com/
There's also some Blend behaviors and helpers to make using it even easier:
http://physicshelper.codeplex.com/
I have drawn tiles in my XNA game and loaded my character. My character, however, doesn't move- the map does, which gives it the illusion of movement. Now I am wondering how to actually test against them for collision. I mean, where does the collision code go and how do I make all tiles represent 'one big thing'?
There's a tutorial on pixel based collision detection on XNA Creator's club. You'll need to figure out what objects you want to do collision detection on. I guess you want the character to move across the tiled background, so you don't want to check for collision between your character and the background. Instead you should make any obstacle s sprites and do collision detection on those.
You might have a look at Nick Gravelyn's Tile Engine Tutorials, it goes through the whole process of creating a tile engine. There's a link here to see all the tutorials on YouTube.
You could have a look at the Platformer Starter Kit, it shows how to organize tiles in a map and check for collisions.
Rectangles have a intersects method. If your player is centered and you know the coordinates, loop through the other texture2ds and check for an intersection before scrolling the map.