I want to create a 2d game in C# using XNA. There should be stickmen who can wear different weapons like a pistol, a grenade or a rocket launcher. And those stickman also should be able to do other things, like drink a bottle of beer and stuff.. So how do you create and store these animations (drink a bottle of beer, walk, throw a grenade) and how can you tell them how to hold a weapon (pistol: in the hand, grenade: in the hand, but holding the arm behind them, rocket launcher: on the shoulder)? What's the best (simple and extensible) approach to this?
For stickmen, comes to my mind, skeletal animations with directly rendered bones. Such vector graphics would scale very well compared to sprites. Skeletal animation stores a tree of bones with lengths and angles, and interpolates between predefined keyframes. The advantage of this is that you can easily incorporate some simple physics and inverse kinematics that blend with the animations (take a look at Jakobsen excellent Verlet dynamics paper) for holding weapons, beer cans and mantling ledges, etc. This is fairly advanced stuff, much easier than 3D graphics, but it will still take you a long time to design and implement.
One thing that can help when compositing sprites (giving a hero a sword, etc) using SpriteBatch is the Origin argument on some of the Draw method overloads. It allows you to rotate around something other than the top left corner and can also help when positioning sprites that are of differing sizes. Since the Origin is specified in source texture scale, any calculations will be valid event if the sprites are drawn at a different scale.
What you're asking is a fairly broad question. You might want to have a look at the 2D Platformer sample that comes with XNA Game Studio. That can get you started.
Related
I am kind of new to unity,to any kind of engine,actually.
I am trying to find a way to have a controllable mass of fluid,i mean to be able to go forward,back and so on using the arrow keys.
At first i thought about having some kind of mesh filled with simulated liquid but it doesn't really fit for my project....
Long story short, i need to be able to move a droplet of water.
I think you should start with instantiating just a lot of balls (2d or 3d) - as a representation for droplets. You can give them all physics colliders and rigidbody mass and you will be able to control them all, by proximity or individually.
In the future you can replace spheres with some kind of surface-generating algorithm like metaballs or raymarching
I'm a beginner programmer and new to Unity. I'm currently practicing hexgrid building with Unity5. My current hexgrid consists of flat hexes, which have either a grassland or ocean 2D texture.
(Current hexgrid)
I'd like to have a sandy shoreline in my hexgrid (on grassland tiles which have ocean tiles as neighboring tiles).
My question is: what is the best, most efficient way to implement this?
I thought of making a texture for each possible shoretile, but that would be about 64 different textures depending how many ocean tiles the grassland neighbors and from which direction.
I also need "blurry" texture lines between desert and grassland hexes and deep ocean and shallow ocean hexes, and I have no idea how to do that...
Any advice is appreciated. Thanks!
I think you should only need 4 or 6 textures. With hexes you can only have two scenarios in a land/sea corner. Either the shoreline is forming a peninsula (convex land/concave sea) or a fjord (concave land/convex sea).
So two main trapezoid textures that paint a beach from the tile edge inwards would cover all land-beaches on peninsulas and all sea-beaches on fjords.
In the opposite case you'd just need a small triangular extension of that texture to fill in the gap between the trapezoids.
This is what I mean: http://imgur.com/08qlJMy
Source: I once tried to figure out how Alpha Centauri draws its terrain by analysing the texture files. I'm reasonably sure that's how they did it.
As for handling a desert, grass, sea corner I believe they first blended the land terrains and then overlayed the shoreline.
i'm developping a 2D Game for Windows Phone, for now i have a Xml parser that i used to config maps and draw items.
Maps are farms. My question is : Once i have all my items drawn, i d like to check collision. How can i define a control ( like a rectangle on my item ).
here the list of my items :
these items are store in a list with X and Y coords.
(I'm not using Xna, should I ?)
Thanks for your help.
It is not strictly necessary to use XNA, but if you're serious about learning game development on Phone/Windows/Xbox devices, it's a must.
Btw collision detection can mean multiple things. It may be based on distance or it may be based on shape intersection. For instance, you may define a shape that loosely surrounds a character, and another that (loosely?) surrounds a touchable item, or a tile, or a wall, then there is collision if those shapes intersect.
You can find info about collision detection algorithms everywhere, even on Wikipedia (http://en.wikipedia.org/wiki/Collision_detection).
Good luck! But give that XNA a spin. It takes a while to get used to but every minute you invest in it pays itself back again and again.
I'm working with xna in C# and in my game I will have a variety of space ships flying all over the place. They will each have an arbitrary rotation, size and position in space and I need a method to determine when they collide. Ideally the method would take two Rectangles, two doubles and two Vector2s for size, rotation and position respectively and return a boolean that indicates whether they have intersected or not.
Have a look at these links:
Collision Detection Overview
Collision Detection Matrices
Putting Collision Detection Into Practice
They show you a way to do pixel-based collision detection, which is more accurate than rectangle-based for irregularly shaped objects.
Update 2021-01-17 (Martin Senne)
Links of XNA have moved to
XNA
XNA - Collision
You could also consider just using an out of the box solution for this and integrating something like the Farseer Physics Engine:
http://farseerphysics.codeplex.com/
These rectangles you describe are called OBB (Oriented Bounding Boxes)
The way to do collisions between them is using the 'Separating axis theorem'
A really nice page describing it in detail with lots of pictures can be found here
I'm designing a 3D game with a camera not entirely unlike that in The Sims and I want to prevent the player character from being hidden behind objects, including walls, pillars and other objects.
One easy way to handle the walls case is to have them face inwards and not have an other side, but that won't cover the other cases at all.
What I had planned is to somehow check for objects that are "in front" of the player, relative to the camera, and hide them - be it by alpha blending or not rendering at all.
One probably not so good idea I had in mind is to scan from the camera to the player in a straight line and see if you hit a non-hidden object, continuing until you reach the player. Unfortunately, I am an almost complete newbie on 3D programming.
Demonstration SVG illustration < that wall panel obscures the player, so it must be hidden. Another unrelated and pretty much already solved problem is removing all three wall panels on that side, which is irrelevant to this question and only caused by the mapping system I came up with.
What I had planned is to somehow check for objects that are "in front" of the player, relative to the camera, and hide them - be it by alpha blending or not rendering at all.
This is a good plan. You'll want to incorporate some kind of bounding volume onto the player, so the entire player (plus a little extra) is visible at all times. Then, simply run the intersection algorithm for each corner of the bounding volume.
Finding which object is at a given point on screen is called picking. Here's an XNA link for you which should direct you to an example. The idea is that you retrieve the 3D point in the game from the 2D point, and then can use standard collision detection methods to work out which object is occupying that space. Then you can elect to render that object differently.
One hack which might suffice if you have trouble with the picking approach is to render the character once as part of the scene, and then render it again at the end at half-alpha on top of everything. That way you can see the whole character and the wall, though you won't see through the wall as such.
One easy way, at least for prototyping, would be to always draw the player after you draw the rest of the scene. This would ensure that the player is rendered on top of anything else in the scene. Crude but effective.
Create a bounding volume from the camera to the extents of the player, determine what objects intersect that volume, and then render them in whatever alternate style you want?
There might be some ultra-clever way to do this, but this seems like the pretty straightforward version, and shouldn't be too much of a perf hit (you're probably doing collision every frame anyway....)
The simplest thing I can think of that should work relatively well is to model all obstacles by a plane perpendicular to your ground (assuming you have a ground.) Roughly assuming everything that is an obstacle is a wall with some height.
Model your player as a point somewhere, and model your camera as another point. The line in 3d that connects these two points lies in a plane that is particularly interesting to you, because if this plane intersects an "obstacle plane" below the height of the obstacle, that means that that obstacle is blocking your view of the player point.
I hope thats somewhat clear. To make this into an algorithm you'd have to implement a general method for determining where two planes intersect (to determine if the obstacle is tall enough to block view.)