Results 1 to 7 of 7

Thread: Custom variables in an object of an object.

  1. #1

    Custom variables in an object of an object.

    I don't know how else to describe it, so I'll try to make myself clear through a series of code snips.

    Exhibit A: My object of a TImageSprite (From Andorra 2D)
    [pascal]
    TCloud = class(TImageSprite)
    private
    protected
    procedure DoCollision(Sprite:TSprite; var Done:boolean);override;
    procedure DoMove(timegap:double);override;
    public
    xspeed,yspeed: integer;
    end;
    [/pascal]
    Notice my xspeed and yspeed integers. The problem is, I don't know how to access them.
    If I do the below, my variables are not accessible..
    [pascal]
    Sprite: TImageSprite;
    Sprite := TCloud.Create(engine);
    with Sprite do
    begin
    Image := imgs.Items[1];
    x := 0;
    y := 0;
    z := 1;
    //xspeed := 0; // Nope. Doesn't exist.
    CollisionTester := ColTest;
    end;
    [/pascal]
    I have a very sneaking suspicion this is because I can only have the properties, etc, of a TImageSprite, but still, since I created it as my own object with new variables, I had hoped I'd be able to access them.

    - Sighs -
    In somewhat related news, I gave up on SDL after I discovered through massive trial and error that I could not load a PNG with alpha, then change that alpha later on to change the opacity.. so I went back to my other friend, Andorra.

  2. #2

    Re: Custom variables in an object of an object.

    Use either

    [pascal]with TCloud(Sprite) do[/pascal]

    or

    [pascal]with Sprite as TCloud do[/pascal]

    or make your Sprite type TCloud instead of TImageSprite.

  3. #3

    Re: Custom variables in an object of an object.

    The problem is that you declared Sprite as TImageSprite but you could change its type to TCloud in order to access new members of the inherited class.

    And as for SDL:
    If I unterstand you correctly, you have and PNG image with alpha channel and want to create an alpha effect using SDL_SetAlpha? That should be work using something like this (Pseudo-code):
    [pascal]
    var LoadImage, DrawImage: PSDL_Surface;
    ...
    LoadImage := IMG_Load("path/to/my.png");
    ...
    DrawImage := SDL_DisplayFormat(LoadImage);
    // if you use SDL_DisplayFormatAlpha instead of SDL_DisplayFormat, you cannot chage the opacity
    SDL_FreeSurface(LoadImage);

    // GameLoop
    while (not Done) do
    begin
    SDL_BlitSurface(DrawImage, ...);
    end;

    SDL_FreeSurface(DrawImage);
    [/pascal]
    Assuming of course you are using pure SDL and not SDL + OpenGL. If you are using the latter, just adjust the alpha value when drawing your quad on the screen with glColor4f.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  4. #4

    Re: Custom variables in an object of an object.

    @User137: Perfect!

    @Stoney: Well, I did that, but it doesn't want to play nice. I basically used GIMP to create a PNG image with an anti aliased font (as I know the font won't be available on every system, and didn't want to waste my time with a font lib + including the font for the menu text). Using SDL_SetAlpha, and SDL_DisplayFormat causes that alpha channel on the PNG image to be lost, and a black background is inserted, so I'd also have to key that out, but there goes my beautiful font anyway. (Now, "It's just a font, it's ok for one thing in the entire game to look ugly", well, there are a number of ideas I have that would rely heavily on the ability to load PNG images and change their opacity properly while keeping the default alpha values from the image, and if I can't do this with SDL, I'm going to go elsewhere )

  5. #5

    Re: Custom variables in an object of an object.

    Quote Originally Posted by dazappa
    I basically used GIMP to create a PNG image with an anti aliased font (as I know the font won't be available on every system, and didn't want to waste my time with a font lib + including the font for the menu text). Using SDL_SetAlpha, and SDL_DisplayFormat causes that alpha channel on the PNG image to be lost, and a black background is inserted, so I'd also have to key that out, but there goes my beautiful font anyway.
    That sounds odd, as far as I remember I got that working in a few of my games and I'm also using GIMP to create or edit my images.
    I will try to create an example if I find the time.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: Custom variables in an object of an object.

    Quote Originally Posted by dazappa
    @Stoney: Well, I did that, but it doesn't want to play nice. I basically used GIMP to create a PNG image with an anti aliased font (as I know the font won't be available on every system, and didn't want to waste my time with a font lib + including the font for the menu text). Using SDL_SetAlpha, and SDL_DisplayFormat causes that alpha channel on the PNG image to be lost, and a black background is inserted, so I'd also have to key that out, but there goes my beautiful font anyway. (Now, "It's just a font, it's ok for one thing in the entire game to look ugly", well, there are a number of ideas I have that would rely heavily on the ability to load PNG images and change their opacity properly while keeping the default alpha values from the image, and if I can't do this with SDL, I'm going to go elsewhere )
    Well if you want to play with alpha (and even rotation and scaling) in your games then I'd suggest trying OpenGL thats bundled with SDL in JEDI-SDL. If you try to play with alpha alone even you'll end up just getting frustrated because SDL does not use hardware acceleration for these types of effects. Instead you'd be best to switch to using OpenGL as it does this exclusively, plus it also has a great Ortho (2D) mode which you can draw all your graphics. And you'll find that all your graphics will be much faster too. Faster = More sprites and other effects you can do per frame.

    And back on topic; this is exactly what I do for all my game objects. Something else I do to easy the Create and Free process is make my own MyObject.Init and MyObject.Free (with override procedures so that most of the nitty gritty can be done within these so that I can just focus on my game design and how the objects interact within the main body of code. Less clutter too.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7

    Re: Custom variables in an object of an object.

    Well, rather than getting my hands dirty with openGL directly, I use Andorra. So that's what I've ended up doing, as it's hardware accelerated and does not have problems with setting the opacity of a partially transparent PNG. In the future, I think I will look into using OGL directly for speed, but for my current project that's 320x240, I think Andorra will suffice

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •