Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 19 Jul 2006
Offline Last Active Yesterday, 06:07 PM

#5228901 2D Collision Mask DX9

Posted by renman29 on 13 May 2015 - 11:06 PM

I'm guessing a bool * mask :

bool * mask = new bool[width*height];


Maybe something like this?:


For each y, I'd get the start pixel of the row (cast to BYTE* - pitch is in bytes) like this:
D3DCOLOR* pixline = (D3DCOLOR*)((BYTE*)rect.pBits + rect.Pitch*y);


Then inside the x loop:
D3DCOLOR pixel = pixline[x];


Then set mask to true or false based on alpha bits:
mask[x+y*width] = ((pixel&0xFF000000)!=0x00);

#5224402 Animation Keyframes, Sampling, and Interpolation Questions

Posted by renman29 on 19 April 2015 - 08:05 PM

I would expect if the rotations weren't quite right, the heel would also deviate in the x axis a bit - but if none of the children receive any translations - it is weird that it would only move in the y direction -- unless somehow the rotation deviations were somehow perfectly altering to keep the heel on the x-axis -- in which case I'd be wondering about how it is baking the output data - maybe even wondering about animation-easing having some involvement. (?) 

#5204247 Save/Load in C# XNA

Posted by renman29 on 14 January 2015 - 11:46 AM

Some example code (based on what I do) - doing it this way makes it UAC compliant and I find it simple:

    public class PlayerData
        public int level;
        public Vector2 player_position;
        public int life;
        public int points;
    public class EnemyData
        public Vector2 enemy_pos;
        public Vector2 enemy_vel;
 public int enemy_life;
// IE:
    public EnemyData[] monsters;
    public PlayerData player;
    monsters = new EnemyData[MAX_MONSTERS];
    player = new PlayerData();

public bool SaveGame(int saveNumber) {
    string fileName = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); //CSIDL_LOCAL_APPDATA
    bool success = File.Exists(fileName);
    if (success) { }
    else {               
    bool success = true;
    FileStream fs = new FileStream(fileName, FileMode.Create);                   
    BinaryFormatter formatter = new BinaryFormatter();       
        if (player != null) formatter.Serialize(fs, player);
 if (monsters != null) formatter.Serialize(fs, monsters);
 // etc....
    catch (SerializationException e)        
        success = false;
        Console.WriteLine("Failed to serialize. Reason: " + e.Message);           
    finally { fs.Close();}

public bool LoadGame(string fileName)
    bool success = true;
    if (File.Exists(fileName) == false) { Console.WriteLine("File does not exist: " + fileName); return false; }
    FileStream fs = new FileStream(fileName, FileMode.Open);
        BinaryFormatter formatter = new BinaryFormatter();               
        player = (PlayerData)formatter.Deserialize(fs);
        monsters = (EnemyData[])formatter.Deserialize(fs);
    catch (SerializationException e)
        success = false;
        Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
    finally { fs.Close(); }   
    return success;


Also I found this recently which is probably the preferred way to do it if targeting xbox also:


and demo zip:


#5194166 Managing spritesheets

Posted by renman29 on 22 November 2014 - 02:34 PM

Difference being on how the spritesheet is put together - like if I made the animation cycle so that each frame is spaced equally apart so the animation module can simply change the source rectangle each frame by some even amount -- then I will use a bit more space on the sheet than if all the source rects were packed tightly together(in which case I couldn't use the same technique and would therefore need precise locations for all the animation frames). I guess this wouldn't be an issue if all your animation frames were close to the same size, however if your character is doing really crazy things in each frame it may be easier to use a sprite sheet packer to assemble the sheet and rectangle definitions for you.

  For more compression (data compression) you could use a DXT type compression in video memory. I know in XNA it is just a matter of changing the properties of the texture in the content pipeline but I'm not sure how it is done otherwise. DXT is lossy so is good for background stuff but I don't know if I recommend it for characters that you will see in front of you all the time if a crisp vibrant image is important to you.

Good luck on your project :)

#5193715 Managing spritesheets

Posted by renman29 on 19 November 2014 - 09:55 PM

I'm agreeing with unbird - also I'd say it depends on how much animation data you end up with. Originally for animated characters, I used even rows for each animation (walk row, run row, jump row, etc... ) but I added tons and tons of animations and started hogging the video ram with numerous 4086x4086 sheets. I found a compressed atlas worked better. The only tricky part then is getting the program to recognize which rectangle sections belong to which animation. If you put each animation frame from your sheet on a separate layer in your image editor and use an export layers to files option (however you do it in your editor) - ie: layers: walk1, walk2, walk3, etc... then use a utility like: Sprite Sheet Packer or something similar which will export a space-saving sprite-sheet as well as a .txt file containing all the rectangles. You can parse the .txt file and use the corresponding names and numbers to automatically match up the animation frames to their place on the sheet and save a lot of video ram (and manual work).  

That being said, however, either approach is good for your purposes I think. Only would be necessary to do it that way if video-ram becomes a concern.

#5193563 Orthographic Projection, width/height

Posted by renman29 on 19 November 2014 - 12:07 AM

Maybe change this:

projection = Matrix.CreateOrthographic(Width,Height,near,far);

to something like this:

projection = Matrix.CreateOrthographicOffCenter(left,right,bottom,top,near,far);

Where left is 0, right is width, bottom is height and top is 0 and near could be say -2000 and far +2000 if you really wanted..

Also good to translate the projection -0.5 up and -0.5 left to get good pixel alignment (could just leave view as identity and use a world matrix to move scene)

#5190524 2D game Terraria-like lighting

Posted by renman29 on 01 November 2014 - 02:14 AM

I think you'd do like with light intensity but the same technique applied to all 3 channels of the color: red_level, green_level, blue_level.. One other thing you can try to speed up the algorithm, is to not finish all the lighting calculations every frame. In other words, you do enough to keep up to a desired accuracy rate in each loop (keeping track of where you left off and perhaps even focusing first more on tiles where changes occurred) and then have the alg continue where you left off in the calculations in the next loop. I don't know if I'm right but I suspect this self-correcting style of lighting might not have any distracting artifacts. It's an idea anyway.

#5190348 Faster 2D Lens Flare Occlusion Fade

Posted by renman29 on 31 October 2014 - 07:05 AM

Aha! I got Method 5 working (just using spriteBatch) and the performance is excellent and the fade-out looks great.

I noticed one thing weird, the foreground needed to use an alpha test (otherwise transparent pixels would have depth and be considered occluding) - but the odd thing was that when I applied the alpha test, the depth values had to go from ( 0f  to  -1.0f ) instead of ( 0f  to +1.0f )... but all other rendering still must be 0-1... what the.....?


Oh well, at least it works! Here's how it looks:


#4997297 2d collisions

Posted by renman29 on 04 November 2012 - 03:21 PM

Not sure which types of collision detection would be most useful to you. If you're doing 2d tile platformer these might help:
Types of tile based collision methods:
Pixel perfect collision detection:
Here you can find rectangle-based collision detection source code - also links to pixel-collision and others:

I'm thinking rectangle-rectangle collision detection works for most things (but may want to try bounding-circle [radius-overlap] for some things)

#3865299 D3DXMatrixMultiply implimentation?

Posted by renman29 on 02 January 2007 - 09:15 PM

Most impressive. :)