Framework Mods

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Framework Mods

Post by thetoddfather » October 24th, 2012, 9:28 pm

Hey Asimov and others,

Was having a good old discussion on enhancements to the framework with Asimov and wanted to pick his brain more on what he's done to make a more robust game using the framework.

So, Asimov, first off congrats on catching that little break ;) There aren't many feelings in this life greater than solving a frustrating glitch in your program and seeing it perform exactly as you intended. Can't wait to see where you take this little game.

Your last post on the framework enhancments you've made to make this game possible was:
I learnt a lot from watching Chillis tutorials, and found I was confident enough to write my own sprite routine. I made a sprite class. My class will handle animated sprites, and non animated sprites.

I load in the sprite sheet and my routine basically offsets to the next image. When it gets to the end it begins again.

I call my animated sprite with this
Turret.Sprite(380,520,100,&gfx);

and here is a section of my sprite class

Code:

bool SpriteLoader::Sprite(double x,double y, float Frametime,int delay,D3DGraphics* gfx, Timer timetest[])
{
DrawSprite((int)x,(int)y,gfx);

timetest[2].StartTimer(delay);
if (timetest[2].TimerCheck())
{

if (Time==0)
{
endtime= clock()+Frametime;
Time=1;
}

if (clock()>=endtime) {
Frame=Frame+1;
Time=0;
}

if (Frame==NumberOfFrames) {
Frame=0;
timetest[2].ResetTimer();
return false;
} // This starts the animation again
}
return true;
}



However my sprite class is huge now, as I have written all kinds of stuff in there. I also wrote my own font class which does non proportional fonts.

As for sound I started with chillis original class and added new functions to do sound looping, and to play and stop sound.

Couldn't have done it without chilli though.
I was curious about this. You say you call the function with "Turret.Sprite(380,520,100,&gfx);", but this seems to be a different function than the one in your code block. Is there another function that calls the SpriteLoader::Sprite function?

Also I am curious about what your Timer class is doing in this function. I can see you've got an instance of Timer you are using called timetest[2]. It seems at least in this function you only use one, are there other places you need this to be an array? Or is there really no reason for it not to be just Timer timetest? So you have a function called Timer.StartTimer(delay). What does delay do? Make the timer wait a period of time before starting? Same with TimerCheck(). What is it looking/checking for? Because it is in an if statement I am guessing it returns a true/false bool?

Sorry for the long windedness, trying to step through this code and see what's happening. I can see how you are stepping through each frame using the clock(). I am guessing the variable Time, not Timer (as in if (Time==0)) is acting as an on/off switch (bool).

As I read it, this function gets called once a frame? It immediately Draws the sprite at x,y, then makes it's changes for next frame. Am I close here?

LASTLY lol, I can see from Missle Command you are making good use of the resource file ;). I am using XN Resource Editor and am curious as to how you do transparent colors for cons and such. I am guessing you have loaded the mountains and background and cities and such using resource files. Could you point me to any tutorials or good links or have any advice on using the editor and resource file effectively in express? I have loaded ICONS, but can't get transparency. Have not yet attempted anything beyond that and would greatly appreciate any help you can offer in this arena.

Thanks!!!
Toddfather.

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Framework Mods

Post by Asimov » October 24th, 2012, 10:15 pm

Hi Todfather,
I was curious about this. You say you call the function with "Turret.Sprite(380,520,100,&gfx);", but this seems to be a different function than the one in your code block. Is there another function that calls the SpriteLoader::Sprite function?
Right I will explain. I only posted one function in my sprite class. My sprite class is called SpriteLoader. This same class can be used for all the sprites in the game so you need to make instances of the same class.

So in my game.h file I set instantiate the class with this
SpriteLoader Turret;

so then I can access functions in the class by calling Turret.Sprite(380,520,100,&gfx); which calls the Sprite function. Before I call the sprite function I have to load the sprite though and I use this
Turret.LoadSprite(L"data//animatedTurret",41,63,20,861);
which loads from a file or this if I want to load from a resource
Turret.LoadSpriteRes(IDR_TURRET,41,63,20,861);

As you can see I have two functions in my class. One to load from resources and one to load from file. I use load from file to quickly test if sprites work before I add it to resources.

My Sprite class has overloaded functions eg
Turret.LoadSpriteRes(IDR_TURRET,41,63,20,861);
City.LoadSpriteRes(IDR_CITY,50,38);
They look like they are calling the same function, but they are not. One is an animated sprite and one is a static sprite.

Right my timer routine was setup before I started using timeDelta. In parts of my program I actually used 3 timers which is why I use an array of timers. Sometimes I need to time more than one item, as you can't just pause the program to run things at different times. However now the array is almost redundant since I have added deltaTime. I could have changed my timer routines in my Sprite array to timeDelta as well, and later I may do this, but this works for now. Best to get things working and then fine tune later. It is important to time everything to the clock or timeDelta, or your game will run at different speeds on different framerates.

Right I get transparency because all my sprites are actually pngs. PNGs have an alpha channel.
A while back Chilli gave me some code which showed an example of using GDI to load PNGS. I took this and implanted it into my SpriteLoader routine. Then later with Chillis help I got my Spriteloader routine to load transparent PNGS. It is a bit complicated to explain exactly. I think Chillis latest tutorial is starting to discuss making alpha channels work. I can go into more detail later on this if you like.

Sorry if I rushed these explanations. I am a little tired heh heh. Probably best if you ask one question at a time and we can get one thing working at a time.

I hope this has given you some insight.
I haven't done any programming for 2 weeks, because I have been poly modelling. Also I have been a little over worked at work lately, so I have been a little tired.

Let me know what you need help with first, and perhaps I can post some of my code.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Re: Framework Mods

Post by thetoddfather » October 24th, 2012, 11:17 pm

Actually, this was a lot of help.

I guess at this stage of the game really my only questions might be about whether I should be looking into timeDelta more? This is the first I have seen on this, or any usage of timers, when timing anything within my programs at this point I create a custom variable that counts frames. If there is a better way I should be diving into now let me know.

When you have some spare time and aren't too tired, I wouldn't mind a little more info on loading pngs and transparency in resources. I have loaded them fine using the loadspritealpha stuff we have used (Loading from files), but am quite interested in making better use of resources like you have. When playing around with the editor I did not see an option to load png files, and when using their tools I could not 'draw' transparent pixels, similarly, I cannot copy and paste from a png in photoshop. It simply writes the transparent pixels as white. So, I am not sure about that stuff quite yet.

And soon I will be bugging you for some guidance on BGM functions ;) I'll see how far I can get with my training wheels still on though haha.

Thanks for the reply though, it did help clear some important stuff up for me.

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Framework Mods

Post by Asimov » October 24th, 2012, 11:42 pm

Hi Todfather,

Give me a few days and I will post some of Png loading stuff.

I have been programming for many years, but only recently directx, so that is new to me. Also anything to do with maths I am rubbish at LOL, but I usually get around it with trial and error and lots of google, and Chilli and Lux heh heh.

If you are new to programming I wouldn't worry about timeDelta yet. I can also show you how I implement that later. I didn't add timeDelta to my game until much later. The whole point of timeDelta is that your game runs the same speed on any machine. You see the game is tied to the framerate, and if somone uses a faster or slower screen your game will run faster or slower.

There is no real need to add it at the early stages while you are learning, but if you wanted to release your game then you would need to think about it.

When my game is finished I am going to release it free on my website.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Re: Framework Mods

Post by thetoddfather » October 25th, 2012, 12:07 am

Sounds great.

I have been learning c and c++ for about two years now off and on. Chili is my first experience in directx. I made a small roguelike game that was not too shabby, but it was all console based. Taught me the basics of game making and c/c++. I am working toward making some little fun games. See where it takes me. Just want the tools to be able to make the games I enjoy, and I have a son I enjoy making little things for him to tinker around with. No HUGE ambitions yet although this is certainly a passion for me.

I have lots to keep me busy, so don't feel rushed to get to my enquiries haha. Just quite interested in how you pulled off some of the things you've done in your game. I can see from your site you have extensive experience in both coding and the art side of things. So, stuff like your fonts, animations and such are definitely where I would like to be moving toward in my quest to be a better game creator.

Anyway, I'll keep an eye out for any updates you throw at me.
Toddfather.

Post Reply