Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Jul 2006
Offline Last Active Sep 09 2015 07:20 PM

Posts I've Made

In Topic: Creating a fancy weapon slot system for my game

26 August 2015 - 01:08 AM

I agree that data based determination is often the best route, although...

one might caution sometimes direct coding is actually a better(faster) approach where data based can in and of itself complicate code more than it otherwise would need to be for the given scenario. There are often occasions that I have seen where it is actually far simpler to code the desired functionality than to create external entities which need to be loaded and understood by the code. In fact I've seen ppl (and done it myself) put together editors/interpreters where it actually takes longer to edit the entities in the gui (and must save and load and be deciphered) than to simply enter the needed data directly into some cleverly designed Macro/function/method.


I try to avoid superfluous coding -- saves a lot of time, less to look at, and easier on the eyes. Sometimes direct is less work and less code.


I actually ended up scrapping some of these external approaches in favor of direct coding since it was actually much faster productivity and easier to test. Why build script systems, editors, etc -- when direct source code is (sometimes) faster and easier? Sometimes it is [ in which case the source code is the editor (not the best for teams tho) ]

For example, I actually made a flash animation type system in which everything is built entirely with source code(methods combos) which actually turned out to provide precise results and fairly fast production. ( I don't recommend this for everyone )

Whatever is faster in the long run.

In Topic: Creating a fancy weapon slot system for my game

24 August 2015 - 06:25 PM

For pointing the gun such that the arm and gun rotate and gun ends up pointing in the aim direction...

Maybe find the vector that represents the shoulder to the back of the gun(distance) and the vector that represents the path from the back of the gun to the nozzle.

Then rotate them as an adjoined pair of vectors toward the aim vector. This could get tricky if the aim is suddenly on the opposite side (in which case you'd want to find the shortest angle between gun-barrel-direction vector and aim position (where aim vector in this case is vector between back of gun and target). Then once the gun is rotated at the appropriate distance toward that aim angle (could use a smoothing technique like newAngle = 0.3f * angle_difference; //30% current difference to smoothen(ease) out rotation changes)

Then you would rotate the arm so the hand is positioned over the handle (the handle should be the appropriate distance cuz we rotated at a distance that we expect the back of the gun to be at). One thing you can do with this is find the vector from shoulder to new handle position and use the vector's angle to assign the current arm rotation.

It works in my head anyway - lol ;)

Btw to add the bullets at the nozzle you would use something like this:


Quaternion aimQuat = Quaternion.CreateFromYawPitchRoll(0, 0, rotation); // rotation of gun
Vector2 bullet_offset = Vector2.Transform(gun_nozzle_offset, aimQuat);      // (ie: gun_nozzle_offset = Vector2(30, -2)  ) 
bullets.Add(new Bullet(pos + bullet_offset, vel+aim_direction*bullet_speed)); //add bullet at gun at correct velocity (player velocity + bullet velocity)   


Something like that anyway - although it may require some alteration to fit with your code.

In Topic: Scrolling background logic?

23 August 2015 - 08:51 AM

Another technique for horizontal and vertical background wrapping is to use UV linear wrapping state with the device so you only need to draw the background once and the hardware takes care of the wrapping.

First you need to figure out how to create a background that when wrapped - it won't appear to have seams. This can be done by copying the background to 4 layers with each layer moved to a corner with their tips touching in the center to expose the seams that would show when scrolling. Then with a 50% opaque stamp tool, smudge tricks and other art techniques to hide seams. Now this art can scroll without seams appearing.

  Then when rendering a texture, you would want the sampler state to use linear wrapping and when you draw it:

(using SamplerState.LinearWrap)

Draw(background, screenRect, new Rectangle((int)background_pos.X, (int)background_pos.Y, background.Width, background.Height), ColorTint); 


Where screenRect is your destination screen rectangle(always the same), and the other rectangle is the source rectangle (x,y, width, height). When the source sampling starts at x, y and exceeds the edges of the texture (cuz trying to go width and height), it will wrap the texture to continue sampling. So then when the player moves you just change background position in that direction.

For layers the same technique could be applied.

Hypothetically, for huge mapped backgrounds, you may want to seamlessly tile parts together and scroll through sections of the grid -- each tile in the grid can tell it which part of which background art to show. This way you could have extensive changes to background scenery as the foreground scrolls.

In Topic: The best way to manage sprite sheet animations?

15 August 2015 - 10:07 PM

(Just want to add) There are occasions when a string matching is (initially) useful - such as external animation editor which may have some unknown # of named animations and behavior definitions which the code knows how to use. You can pre-cache (store ahead of time) a match to a logic(if then conditions) determined animation. If you want to keep the string format, you can use an unordered map or dictionary (hash tables - very fast) to match the name/description with the desired animation. For animations that will switch frequently though you may want to have it store the matches ahead of time (micro-optimization) to the appropriate enums.

Good luck on your mission. :)

In Topic: The best way to manage sprite sheet animations?

12 August 2015 - 07:18 AM

haegarr: that's brilliant and quite helpful. :)