Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Vincent

Pages: 1 ... 39 40 [41]
601
Help, Errors, FAQ / Re: Sprite priority question
« on: 2008-01-22, 01:59:57 PM »
Well, finally I got one step further.  I realized that m_Sprites was read-only because the was no "Set", only "Get".  So I changed the code into SpriteCollections.cs to implement a "Set".  I'll keep you informed!

602
Help, Errors, FAQ / Re: Sprite priority question
« on: 2008-01-22, 01:04:02 PM »
Hi again!

I continued my work on the sprite priority functions and, as it may interest some people who might run into the same problems than me, I'll explain what I've done.  By the way, when I'm done, maybe bluemonkmn could make my code file available ont the sgdk2 website for others to use! :)

I worked on another "sprite priority function" that allows the insertion of a sprite right on the of another specfied one.
Example:
My collection of sprites contains
  -Sprite1
  -Sprite2
  -Sprite3
  -Sprite4

This functions allows to insert a Sprite 4 over Sprite1 without having to make multiple uses of the SwitchSpritePriority function.
With SwitchSpritePriority, you would have to make 2 uses of the (switch Sprite4 with Sprite3, then switch Sprite4 with Sprite2).
With InsertSpriteOnSprite, you just specify which sprite must be moved (Sprite4) and which is the sprite that is supposed to be right under it (Sprite1)
Both should give a final result of:
  -Sprite1
  -Sprite4
  -Sprite2
  -Sprite3

And, I would really like to test these 2 functions, but they both get the same error that I specified before.  Which is:
Quote
Library\Projects\TKDremake\SpritePriorityFunctions.cs(26,10) : error CS0200: Property or indexer 'SpriteCollection.this[int]' cannot be assigned to -- it is read only
Library\Projects\TKDremake\SpritePriorityFunctions.cs(27,10) : error CS0200: Property or indexer 'SpriteCollection.this[int]' cannot be assigned to -- it is read only

Here is the code of my custom class:
Could someone help me out?

Code: [Select]
using System.ComponentModel;

namespace CustomObjects
{
   // added by Vincent
   public class SpritePriorityFunctions
   {
      [Description("Switch the priority of sprites")] 
      public void SwitchSpritesPriority(SpriteBase FirstSprite, SpriteBase SecondSprite)
      {
         int i;
         int iFirstSprite;
         int iSecondSprite; 
         for (i = 0; i < FirstSprite.ParentLayer.m_Sprites.Count; i++)
         {
            if (FirstSprite.ParentLayer.m_Sprites[i] == FirstSprite)
            {
               iFirstSprite = i;
            }
            if (FirstSprite.ParentLayer.m_Sprites[i] == SecondSprite)
            {
               iSecondSprite = i;
            }
         }
         SpriteBase tempSprite = FirstSprite.ParentLayer.m_Sprites[iFirstSprite];
         FirstSprite.ParentLayer.m_Sprites[iFirstSprite] = FirstSprite.ParentLayer.m_Sprites[iSecondSprite];
         FirstSprite.ParentLayer.m_Sprites[iSecondSprite] = tempSprite;
      }

      [Description("Inserts a sprite right on top of another specified one")] 
      public void InsertSpriteOnSprite(SpriteBase SpriteToInsert, SpriteBase SpriteRightUnder)
      {
         int i;
         int iSpriteToInsert = -1;
         int iSpriteRightUnder = -1; 
         
         //Detecting where are the sprites in the list
         for (i = 0; i < SpriteRightUnder.ParentLayer.m_Sprites.Count; i++)
         {
            if (SpriteRightUnder.ParentLayer.m_Sprites[i] == SpriteToInsert)
            {
               iSpriteToInsert = i;
            }
            if (SpriteRightUnder.ParentLayer.m_Sprites[i] == SpriteRightUnder)
            {
               iSpriteRightUnder = i;
            }
         }   
         
         //Don'tdo anything if the values are not correct
         if (iSpriteToInsert != -1 && iSpriteRightUnder != -1)
         {
            //Don't do anything if everything is already ok
            if (iSpriteRightUnder != iSpriteToInsert - 1)
            {
               //We must change the list from the iSpriteToInsert index to the iSpriteRightUnder index
               if (iSpriteToInsert < iSpriteRightUnder)
               {
                  for (i = iSpriteToInsert; i < iSpriteRightUnder; i++)
                  {
                     SpriteRightUnder.ParentLayer.m_Sprites[i] = SpriteRightUnder.ParentLayer.m_Sprites[i + 1];
                  }
                  SpriteRightUnder.ParentLayer.m_Sprites[iSpriteRightUnder] = SpriteToInsert;
               } 
               //We must change the list from the iSpriteRightUnder index to the iSpriteToInsert index
               if (iSpriteToInsert < iSpriteRightUnder)
               {
                  for (i = iSpriteToInsert; i > iSpriteRightUnder; i--)
                  {
                     SpriteRightUnder.ParentLayer.m_Sprites[i] = SpriteRightUnder.ParentLayer.m_Sprites[i - 1];
                  }
                  SpriteRightUnder.ParentLayer.m_Sprites[iSpriteRightUnder + 1] = SpriteToInsert;
               }         
            }
         }       
      }
   }
}

To bluemonkmn:
I read the code in the SpriteCollection file, and I realized that playing with the order of the sprites in the m_Sprites collection could cause some problems with the fact that the sprites considered static and the sprites considered dynamic may get messed up.  Maybe it would be interesting to alter this system in a future release.  Or maybe you have a better way to handle this situation?  I am all ears!  ;D

By the way, I'm having a great time using SGDK2!  :)

603
Help, Errors, FAQ / Re: Sprite priority question
« on: 2008-01-22, 10:45:36 AM »
Hi guys!

Thank you for all the info.  I couldn't work on this for the past 3 days, but now I'm back.  So, I changed my function to this:
Code: [Select]
public class SpritePriorityFunctions
   {
      [Description("Changes the priority of sprites ")] 
      public void SwitchSpritesPriority(SpriteBase FirstSprite, SpriteBase SecondSprite)
      {
         int i;
         int iFirstSprite;
         int iSecondSprite; 
         for (i = 0; i < FirstSprite.ParentLayer.m_Sprites.Count; i++)
         {
            if (FirstSprite.ParentLayer.m_Sprites[i] == FirstSprite)
            {
               iFirstSprite = i;
            }
            if (FirstSprite.ParentLayer.m_Sprites[i] == SecondSprite)
            {
               iSecondSprite = i;
            }
         }
         SpriteBase tempSprite = FirstSprite.ParentLayer.m_Sprites[iFirstSprite];
         FirstSprite.ParentLayer.m_Sprites[iFirstSprite] = FirstSprite.ParentLayer.m_Sprites[iSecondSprite];
         FirstSprite.ParentLayer.m_Sprites[iSecondSprite] = tempSprite;
      }
   }

I really believe it should work but it won't compile.  It gives me this error:
Quote
Library\Projects\TKDremake\SpritePriorityFunctions.cs(26,10) : error CS0200: Property or indexer 'SpriteCollection.this[int]' cannot be assigned to -- it is read only
Library\Projects\TKDremake\SpritePriorityFunctions.cs(27,10) : error CS0200: Property or indexer 'SpriteCollection.this[int]' cannot be assigned to -- it is read only

Have I done something wrong?  Or is it just impossible to replace the sprites in this collection?

Thanks!

604
Help, Errors, FAQ / Re: Sprite priority question
« on: 2008-01-18, 12:48:17 PM »
Hello again! :)

I tried to make the script function, but I encountered a problem...  Sorry if it is a newbie question:  from the CustomObjects namespace, how can I get to modify the m_Sprites collection?  I can't get to it, maybe I am missing a namespace or m_Sprites is contained within the LayerBase object?

I'm posting my code here, could someone help me out please?

Code: [Select]
using System.ComponentModel;

namespace CustomObjects
{
   // added by Vincent
   public class SpritePriorityFunctions
   {
      [Description("Changes the priority of sprites ")] 
      public void SwitchSpritesPriority(SpriteBase FirstSprite, SpriteBase SecondSprite)
      {
         int i;
         int iFirstSprite;
         int iSecondSprite;     
         for (i = 0; i < m_Sprites.Count; i++)
         {
            if (Sprites[i] = FirstSprite)
            {
               iFirstSprite = i;
            }
            if (Sprites[i] = SecondSprite)
            {
               iSecondSprite = i;
            }
         }
         SpriteBase tempSprite = m_Sprites[iFirstSprite];
         m_Sprites[iFirstSprite] = m_Sprites[iSecondSprite];
         m_Sprites[iSecondSprite] = tempSprite;
      }
   }
}

Thanks a lot!

605
Help, Errors, FAQ / Re: Sprite priority question
« on: 2008-01-18, 11:06:07 AM »
Hello everyone!

Sorry, I've been busy lately and I couldn't answer you!

To Morgengrauen:
I looked at the IsoSample project, but it does have the same problem that I encountered with sprites always showing in front of other sprites rather than showing in front or behind another sprite.  I modified the sample to this on my computer and it is easy to reproduce:  simply add a sprite on level 1 on the main layer.  Then create a Map player 1 to inputs script in the Main layer plan and deactivate the Map player to inputs script in the sprite plan.  (otherwise, when you move the sprite, both sprite move).  Then, you should be able to see the behavior I am describing.

To bluemonkmn:
I'm going to try the modify the source code of my project to include a custom function to make this possible.  I will use the sample project as a reference (I believe you there is a custom object in the sample, I guess it is the exampleI need.)  I guess I'm going to ask you more questions on this, since it doesn't seem documented in the help file. (I'm new to C# too.)

By the way, this is out of the matter at hand (sorry), but I have another quick question.  If I wanted to add more buttons to a player (a max of 4 buttons seems a little limitative), should I alter my project source code in the same way I'm going to do with the sprite priority changing script?

Thanks a lot for your time and advices! :)

606
Help, Errors, FAQ / Sprite priority question
« on: 2008-01-16, 12:34:02 PM »
Hi guys!

I have question related to sprite priority.  I'm quoting the help file here:

Quote
If two sprites have the same priority, the order in which they will be drawn is arbitrarily assigned when the project is compiled, but will never change after that.

In my fighting game, the players sprites can move toward the background and toward the foreground.  Thus, at some times Fighter1 must draw in front of Fighter2 and some times it is the opposite.  I looked around to find a way the change a sprite priority with a script during play, but I can't find anything.  Is there a way to apply the "interleaved" capability between "tiles and sprites" on the same priority to "sprites and sprites"?

Is there another workaround?

Thanks a lot!  :)

607
Help, Errors, FAQ / Re: Animation related question
« on: 2008-01-15, 08:18:33 AM »
No problem guys, when I tested the script, I realized that it was going much too fast.  It's definitely frames of time.  And I will keep in mind to look ofter in the dropdown menu! ;)

608
Help, Errors, FAQ / Re: Animation related question
« on: 2008-01-14, 02:28:40 PM »
Great!  :)

It is working just fine!

What I was missing was that I didn't know it was possible to get the actual frame in the left or right operand dropdown list.

Thanks a lot Morgengrauen!

609
Help, Errors, FAQ / Animation related question
« on: 2008-01-14, 12:55:48 PM »
Hello everyone!

I have a quick question for you guys.  I think I looked everywhere, but I couldn't find an answer.  I'm still working on my fighting game project and I was wondering how it would be possible to detect, during an animation, on which specific frame of a state the sprite currently is. 

Example: my fighter sprite has 2 states, one being normalState and the other one is attackingState.  When the player hits the attack button, the state changes from normalState to attackingState.  Now, this state is composed of 4 frames.  The thing is, how am I supposed to detect when the attack animation has ended (on the 4th frame) to switch the state back from attackingState to normalState?

Or am I confused and not taking the most logic approach?

Thanks for your help!

610
Help, Errors, FAQ / Re: Solidity problem
« on: 2008-01-11, 11:06:08 AM »
I did change the collision rectangle (changing it from 32x32 to 100x100) and it solved the problem!
Thanks a lot!

 ;D

611
Help, Errors, FAQ / Re: Solidity problem
« on: 2008-01-11, 08:43:24 AM »
Hi,

To Morgengrauen:
Do you mean a collision mask?  I believed, from what I read, (correct me if I'm wrong) that it was only use to calculate collisions between 2 sprites?  Since the floor in this case is not defined as a sprite, should it not be relevant?  I will try this in case it would make a difference.

To bluemonkmn:
I just submitted my project files.  I imported some images in it, so it might be a little big.  Tell me if some files are missing: I'm still unfamiliar with the program structure.  By the way, these images will change eventually, I ripped them from a snes ROM to work with something while my friend is actually drawing the real pictures.  So there won't be any copyright problems.

Thanks a lot for your help! :)

612
Help, Errors, FAQ / Solidity problem
« on: 2008-01-10, 03:11:10 PM »
Hi everyone,

Sorry if it is a basic question, but I'm new with SGDK2 and never used SGDK1 so I might be missing some experience or basic concepts, so please indulge me! :baby:

What I'm trying to do:
I'm trying to make a fighting game but not exactly in 2d.  The fighters can move into the background or in the foreground.  So rather than fighting on a single line (the traditional way like Street Fighter 2 - walking left-right, jumping and crouching) they can do all that and move in a semi-isometric way.  (Which is like dodging sideways)  I made a couple of rules so by holding a key the fighters changes from jumping to walking sideways and it works pretty fine but I've got a problem related to solidity.  I explain this problem further down.  There are 3 floors that I've made for the fighter, one in the background, one in the foreground and one between them (all on the same layer).  Depending on the movement entered by the player, the fighter is supposed to react to the solidity of one of these 3 floors.  (I hope I'm not confusing anyone, it is quite hard to explain and my english might not be top notch: I'm a french canadian, so english is my second langage.)

The obstacle I can't overcome for the moment:
For some reason, the fighter is not taking solidity into account.  He falls (beacause of gravity) right through the "supposed" ground.  The thing is that the fighter sprite size is 100 pixels by 100 pixels and the floor tiles are 13 pixels by 14 pixels.  I wonder if this huge difference in size could cause a problem.  I have to say that I followed all the steps the create a normal behavior with solidity (I passed through the tutorial and looked at the sample project) but somethings seems to be missing. 

Here is what I did to create solidity (maybe I did something wrong):
1- I created 3 Tile categories for the floors (MatLow, MatMid and MatHigh)
2- I created 3 Solidity types (One for each)  Each of these solidity specifies one of these floor is to be considered SolidTileShape and the two others are EmptyTileShape.
3- I included the floor tiles in the map layer editor (drawing the 3 floors)
4- In the layer editor, I set the fighter sprite to make him react to one of the three floors by default
5- In the Fighter sprite definition rules I added these rules in this order (maybe the order can be the cause of the problem) (I won't paste each rule's code, but the title of each is quite self-explanatory)
rule 1: scroll player into view
rule 2: inertia
rule 3: animate the fighter to base animation (little jumping on place, the sprite doesn't move, only the images in it)
rule 4: react to solidity
rule 5: snap to ground
rule 6: move by velocity
rule 7: Accelerate by inputs
rule 8: gravity

There are a couple of other rules under certain conditions, but I deactivate them and the problem is still there, so they should not be related to this problem.

Presently, I can make the character move around the mat, jump, etc, but he always falls through the ground.

Is there something I am missing?  Do you need to see the project file to have a more precise idea?  If someone asks me for it, I would gladly share or show what I've done, but the game is still in it's very early development phase!

Thank you for your time!  :)

Pages: 1 ... 39 40 [41]