Thread: I need help with switches plz

  1. #1

    I need help with switches plz

    I am writing a function that draw images to the screen. I already got the function to actually DRAW the images, but normally you would have to make a structure and load the images for EVERY function you make that draws pictures, I am making it to where you call this function, DrawSprite(), and it loads everything up and all that junk. One of the arguements is called sprite, which is a string. You put that arguement in, and there is a switch that will see what you put in (for example: T_grass) but for some reason the switch won't except strings, it says Case does not return an Integer. Is there any way I can make it read strings? I tried just making a bunch of if statements, but anything under a 200 MHz computer takes forever to draw the images. Now a switch would make it a LOT faster.

    If a switch is not the answer for this, what else could I do?

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    did u put the cases in quotation marks? If that didn't work u could maybe u could try to convert the strings into character arrays and do the same thing. If not, I am not really sure how you could do it without if statements.

  3. #3
    I am using this:

    char sprite[40];

    And yes, I already put the quotation marks, I used the " " ones because it has more than one character in it.

    If I use if statements, as I said earlier, all the images near the bottom take a LONG time to load. I waited 12 seconds for a small picture to load!

  4. #4
    I really dont understand the question, posting some code might help clarify things. But from what I think I understand, passing the string through a hash function might do the trick.

    void Draw(char sprite[40])
        long hashval = crc32(sprite);  // or whatever funtion you want
            case HASHVAL_SPRITE1: // calc the hash vals ahead of time
            case HASHVAL_SPRITE9:
    or instead of using a string, use an enumerated type:

    enum SPRITE {SPRITE1, SPRITE2...};
    void Draw(SPRITE sprite)
           case SPRITE1:
    again, im not sure I understood your question. So if I'm is way off, just ignore me

  5. #5
    thx, but I am very rusty on enums and hashes. The enum looks the way to go. Ok, how to I call the function? Do I call it like a normal function i.e. Draw(SPRITE1)?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. switches and classes... so very very confused :( plz clarify
    By MegaManZZ in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2008, 01:10 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM