lodoss118

Members
  • Content count

    315
  • Joined

  • Last visited

Community Reputation

102 Neutral

About lodoss118

  • Rank
    Member
  1. XNA Custom Sprite Sorting on Z Plane

    thanks mate seems to be working fine now
  2. Hi guys i am kinda confused, i have a list of entities which i sort on the z plane (mimic games like final fight depth) i have a IComparer function like this class CEntityComparer : IComparer<CEntity> { public int Compare(CEntity e1, CEntity e2) { float z1 = e1.GetZ(); float z2 = e2.GetZ(); return z1.CompareTo(z2); } } but i seem to get zome z fighting problems when they are probably on the same z plane? and i can't do something like this? class CEntityComparer : IComparer<CEntity> { public int Compare(CEntity e1, CEntity e2) { float z1 = e1.GetZ(); float z2 = e2.GetZ() + 5; return z1.CompareTo(z2); } } i keep getting a nullpointer exception saying that Comparer is inconsistent?
  3. Help with xna and vector 2

    this works public void Draw(SpriteBatch batch) { vectorContainer.X = position.X; vectorContainer.Y = position.Y + position.Z; zLayer = (position.Z/1000); batch.Draw(sprites[currentFrame], vectorContainer, null, Color.White, rotation, Vector2.Zero, scale, SpriteEffects.None, zLayer); }
  4. Help with xna and vector 2

    i am passing my sprites position.Z to the layerDepth attribute but the sprites disappear?
  5. Help with xna and vector 2

    actually this should work vectorContainer.Y = position.Y + position.Z; z is for walking y is for jumping etc... i am doing a manual sort of sprites then rendering them according to thier z value public int CompareTo(Sprite other) { return position.Z.CompareTo(other.position.Z); } public static Comparison<Sprite> SpriteZComparison = delegate(Sprite s1, Sprite s2) { return s1.position.Z.CompareTo(s2.position.Z); };
  6. Help with xna and vector 2

    yes i can see a depth attribute but i was thinking doing something like this class Sprite { public List<Texture2D> sprites { get; private set; } public int currentFrame { get; set; } public List<TimeSpan> timeIntervals { get; private set; } public TimeSpan currentInterval { get; set; } public Vector3 position; public Vector3 velocity; public Vector3 origin; public bool active { get; set; } public float scale { get; set; } public float rotation { get; set; } public float zLayer { get; set; } public Vector2 vectorContainer; public Sprite() { sprites = new List<Texture2D>(); currentFrame = 0; timeIntervals = new List<TimeSpan>(); currentInterval = TimeSpan.FromMilliseconds(0); position = Vector3.Zero; velocity = Vector3.Zero; origin = Vector3.Zero; vectorContainer = Vector2.Zero; active = true; scale = 1; rotation = 0; zLayer = 1; } public void AddSprite(Texture2D sprite) { sprites.Add(sprite); timeIntervals.Add(TimeSpan.FromMilliseconds(0)); } public void SetDelay(int timeSpan) { for (int i = 0; i < timeIntervals.Count; i++ ) { timeIntervals[i] = TimeSpan.FromMilliseconds(timeSpan); } } public void SetDelay(int frame, int timeSpan) { timeIntervals[frame] = TimeSpan.FromMilliseconds(timeSpan); } public void UpdateFrames(GameTime gameTime) { if ((currentInterval += gameTime.ElapsedGameTime) > timeIntervals[currentFrame]) { currentFrame = (currentFrame + 1) % sprites.Count; currentInterval = TimeSpan.FromMilliseconds(0); } } public void Draw(SpriteBatch batch) { vectorContainer.X = position.X; vectorContainer.Y = position.Y + position.Z; batch.Draw(sprites[currentFrame], vectorContainer, null, Color.White, rotation, Vector2.Zero, scale, SpriteEffects.None, zLayer); } } and store sprites in a list and sort them by their z values spriteBatch.begin(); listSprites.sort(interfaceZSort); drawAllSprites(); spriteBatch.end();
  7. Help with xna and vector 2

    i need the z axis as this will be the walking axis and the sorting will be done by this i.e. if player.z > enemy.z then draw play infront etc..
  8. Help with xna and vector 2

    Hi i am trying to make a scrolling beat em in xna, like streets of rage and was wondering how would i use vector 2 to have the z position aswell. For example i need both 3 axis (x, y, z) for this type of game but i want it to pass it as a vector in the spriteBtach draw method?
  9. moving around target/player

    Hi Dek the original code i posted worked fine if i just used SetPosX and SetPosZ which just assigns the x and z values. What i now did was this float rx = (player->GetPosX() + cos(angle + deg) * radius); float rz = (player->GetPosZ() + sin(angle + deg) * radius); float dx = enemy->GetPosX() - rx; float dz = enemy->GetPosZ() - rz; float mag = atan2(dz, dx); enemy->MoveX(-cos(mag)*2); enemy->MoveZ(-sin(mag)*2); now this is perfect, depending on the radius the enemy comes close to the player then once reached the radius, it circles the player :@
  10. moving around target/player

    Kinda but as i am not using vectors i was hoping someone would show me using the moveX and some calculation to do circling around
  11. Hi guys i have 2 methods to move my sprite, moveX and moveZ. What i want to do is move my enemy sprites around a target using moveX and moveZ which just increments the x or z positions i.e x += speed, z += speed. I am not sure if this is right but so far i have this float x = enemy->GetPosX() - player->GetPosX(); float z = enemy->GetPosZ() - player->GetPosZ(); float angle = atan2(z, x); float distance = sqrt(x*x + z*z); enemy->MoveX((player->GetPosX() + cos(angle + deg) * distance)); enemy->MoveZ((player->GetPosZ() + sin(angle + deg) * distance)); enemy->CheckState(::WALK_TOWARDS); i don't think moveX and moveZ will get the right speed to go around target?
  12. moving around target/player

    Hi guys i have 2 methods to move my sprite, moveX and moveZ. What i want to do is move my enemy sprites around a target using moveX and moveZ which just increments the x or z positions i.e x += speed, z += speed. I am not sure if this is right but so far i have this float x = enemy->GetPosX() - player->GetPosX(); float z = enemy->GetPosZ() - player->GetPosZ(); float angle = atan2(z, x); float distance = sqrt(x*x + z*z); enemy->MoveX((player->GetPosX() + cos(angle + deg) * distance)); enemy->MoveZ((player->GetPosZ() + sin(angle + deg) * distance)); enemy->CheckState(::WALK_TOWARDS); i don't think moveX and moveZ will get the right speed to go around target? The behaviour should be something like circling around the player? [Edited by - lodoss118 on May 13, 2010 10:53:34 AM]
  13. Hi guys, i have created a sprite class and what i am trying to do is, basically load a bunch of sprites from a specified folder in the project, and was wondering how i can do this is in xna c#. public void Load(ContentManager content, String asset) { dirInfo = new DirectoryInfo("asset"); FileInfo[] rgFiles = dirInfo.GetFiles("*.*", SearchOption.AllDirectories); foreach (FileInfo file in rgFiles) { Texture2D sprite = content.Load<Texture2D>(file.FullName); spriteList.Add(sprite); } } I am not sure how the content.Load will work with this when getting each file?
  14. 2d game fullscreen and window

    Just realised it was due to when i was scaling the sprites doh :)
  15. 2d game fullscreen and window

    Just realised it was due to when i was scaling the sprites doh :)