Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Windows / VS2010 T2 Menuing system with GetSpriteHit

Author
Message
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 1st Jul 2012 23:57 Edited at: 2nd Jul 2012 01:56
Hello!

Warning : I am new to VS 2010 and C++ so while I am doing my best to make things clean and easy to read if I am doing things wrong please dont be afraid to point them out I'm quite glad to correct my ways.

I am trying to lay down a menu system using the GetSpriteHit() function to determine which button the user clicked on and then call the function that runs that menu.

The program compiles, splash screen loads. MainMenu loads; some times I get a regular pointer, some times I get a spinning "busy" icon (I'm on win7 so its a circular one) but I can not click on my menu button; and even if I do the spinning just keeps going and nothing happens.

I assume I'm handling the C code wrong to pass to the PlayMenu ?




One extra question; I had to modify the template.h file to include the extra function names or the compiler kept complaining that function did not exist in the app ? Is this the right way to do it ?



Thanks in advance!
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 2nd Jul 2012 10:35
I'm not C++ pro either but I'll see what I can do.

One of the problems might be that you're creating the same sprite over again but not deleting it. E.g I'm not sure how AppGameKit handles this:

agk::CreateSprite(501, 501);
agk::CreateSprite(501, 502);

i.e How does AppGameKit handle creating the same sprite again without deleting it? To be safe, you could check for its existence before creating the sprite e.g



Quote: "I had to modify the template.h file to include the extra function names or the compiler kept complaining that function did not exist in the app ? Is this the right way to do it ?"

While that technically works, you can also do this:



Functions are like variables in that they need declaring (but not initializing so you don't have to fill them out until later) before use. Often this is done before the int Main() or in this case, before app::Begin.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 2nd Jul 2012 15:06
@hodgey:

thanks for the feedback ; the prototyping was definitely the answer for the functions -- I had tried that but forgot when your declaring a prototype you include the semicolon ;

So essentially I did it wrong

In regards to the sprite creation; I'm not sure either but I was able to get an app that runs if I take out my while statements?

So I will work on cleaning that up a bit and once I have it just right (or get further stuck I suppose) I'll post an updated version here to share the solution.

Time for work though so that'll be this afternoon.

Thanks for all your help as usual!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jul 2012 17:38
Try this (it creates only if the sprite doesn't exist:


Cheers,
Ancient Lady
AGK Community Tester
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Jul 2012 00:41 Edited at: 3rd Jul 2012 03:18
Quote: "I'm not sure either but I was able to get an app that runs if I take out my while statements? "

Just by reading your code, I can't see any technical reason it shouldn't work (apart from the sprites issue) but it could be restructured. Personally, I prefer to have only 1 loop (app::Loop) to have the sync() in it and have everything else revolve around it. When writing menus, I usually have a LoadMenu(), Menu(), CleanUpMenu(). The LoadMenu() loads the necessary media and sets the necessary variables. Menu() is looped through and contains events. CleanUpMenu() deletes/hides whatever isn't needed once the user has moved on from the menu.

You're welcome.

@Ancient Lady: that's exactly what I meant to type

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 3rd Jul 2012 03:00
In the process of testing now that I'm home


The suggested code actually needed == operator rath an assignment operator (=)

like so:



Trying to play with turning while statements back on to see if the program will have the same problem again since that doesn't appear to be something that *should* cause problems..
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Jul 2012 03:21
Ancient Lady, shame on you for forgetting the comparison operator!

erebusman: you might have to do the same thing with the images as well. ie:



I hope I got the code right that time.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 3rd Jul 2012 03:24
Quote: "Just by reading your code, I can't see any technical reason it shouldn't work (apart from the sprites issue) but it could be restructured. Personally, I prefer to have only 1 loop (app::Loop) to have the sync() in it and have everything else revolve around it. When writing menus, I usually have a LoadMenu(), Menu(), CleanUpMenu(). The LoadMenu() loads the necessary media and sets the necessary variables. Menu() is looped through and contains events. CleanUpMenu() deletes/hides whatever isn't needed once the user has moved on from the menu. "


Well .. I have confirmed ; the while loop is what is causing the 'freeze'.

I left all other image tags "as is" and when I take the while loop the GetPointerPressed function works and takes me to the PlayMenu().

When I put the while loop back in - it stops working again ?

I only know so many ways to write a while loop in C so I'll see what I can do with this I love challenges though!
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Jul 2012 04:45
Quote: "I left all other image tags "as is" and when I take the while loop the GetPointerPressed function works and takes me to the PlayMenu()."

I'm not sure why that's happening. Are you happy to upload the project?

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 3rd Jul 2012 06:28
Yeah I may upload it I have no issues doing that,

I am actually re-writing it taking another approach right now so depending on the results well see if thats neccesary.

I'm doing more what you said about keeping the main loop the sync point and see what happens.

it wasnt my preferred way of handling things but I'm not married to it so just seeing what happens
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 3rd Jul 2012 06:53
So a forum search found this thread which helps under stand my my while loop is causing a problem:

http://forum.thegamecreators.com/?m=forum_view&t=188206&b=41

This is actually a big deal ; it says to me the ONLY way to make a AppGameKit T2 app work is you have to use the Loop() function in the way described in the thread or your app wont work!!

And I got the menu's working with this code:



Note I temporarily turned off the background bitmap for both menus as it was selecting that image ID rather than the NEW or QUIT buttons ID; I think that is a 'depth' issue or something I need to work on but the actual menu flow is working perfectly now.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Jul 2012 07:26
Quote: "This is actually a big deal ; it says to me the ONLY way to make a AppGameKit T2 app work is you have to use the Loop() function in the way described in the thread or your app wont work!! "

Interesting read but it makes sense. I'll remember that one.

Glad you got it working, that's more or less the approach I would use. However, the restriction on the app:Loop() function makes making a pause function interesting. I normally enter a second loop which might cause a crash in this case. I'll have to experiment.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Jul 2012 17:21
Quote: "Ancient Lady, shame on you for forgetting the comparison operator!"


I've been working in Tier 1 way too long!

When I'm doing Perl and PHP programming after working T1, I keep forgetting the closing semi-colon.

Cheers,
Ancient Lady
AGK Community Tester
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 4th Jul 2012 07:04 Edited at: 4th Jul 2012 07:05
The "depth" problem appears to be fixed by having the backgrounds have a lower sprite number.

So in this situation:



You can not click on the NewGame button

But in the second situation


You *can* click on the NewGame button.

I thought the order that mattered was the order in which it was loaded on to the screen ; but I find through observation and testing that appears incorrect.

The version of the AppGameKit documentation I'm using for the examples section has a Sprite Depth page that says the following

Quote: "
Sprite depth
Description

The order in which sprites are drawn is controlled either by the order in which they are created or by altering their depth property. Understanding how this works is important for games that rely on multiple layers of sprites being displayed.
"


This appears to be true in the VISUAL depth meaning the backdrop is always drawn first whether the ID is larger or smaller, but when attempting to determine what has been clicked on the item with the higher ID is being chosen despite the draw order.
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 4th Jul 2012 07:43
Okay simplest question yet I can not find the answer.

I can see the void app::End(void) function is supposed to end your app; but how do I .. end the game? Just call that function?

I got a compile error that End() was not defind when I did that and when I look at the spaceshooter code example they are not calling the end() function either? weird..
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 4th Jul 2012 08:26
Quote: " but how do I .. end the game? Just call that function? "

You don't even need to call it, just fill it out (delete sprites, images, sounds, music etc, free up memory).

If you take a look at the end Core.cpp, it should have App.End() which is called once you exit app::Loop() which is upon a request to terminate the application. It looks like its called when you click the 'X' exit button on the top right corner of the screen as well but I can't confirm that.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 4th Jul 2012 17:59 Edited at: 4th Jul 2012 22:20
@Hodgey;

Okay that makes a bit of sense but here's my bigger question so you know what I meant:

AGK can run on multiple platforms (correct me if I'm wrong though).

- iOS
- Andriod
- Mac
- Windows

In the "mobile" platforms exiting the application through a "home" button or such is the accepted way but on the "desktop" platforms the player needs a way to tell the application to stop OTHER than having to Force Quit (mac) or End Task (windows).

How do I initiate a normal end of the application on platforms that do not have "home" buttons is my bigger / real question?

Thanks in advance!

EDIT: In after thought maybe you did give the answer as I havent gone and read the end.cpp thing yet I'll be doing that shortly ...
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 5th Jul 2012 01:41 Edited at: 5th Jul 2012 01:42
Quote: "How do I initiate a normal end of the application on platforms that do not have "home" buttons is my bigger / real question?"

Ok before I answer this, you should know that I'm not a professional windows programmer (still a 1st year uni student in Computer Science) so I don't fully understand what I'm doing here.

Proceed with caution.



This is the last block of code in Core.cpp and you might notice that it contains App.Begin(), App.Loop(), App.End().

This is the code we're focusing on, the loop which calls App.Loop().


You can see it's a while loop which is kept going when bExitLoop is false and that bExitLoop becomes true when msg.message = WM_QUIT.
A little googling of WM_QUIT leads to this and then to this.

From reading the documentation, it looks like you call PostQuitMessage(0) to exit. 0 being a normal (successful) exit code.

It seems to work and the output shows the exit code of '0x0' which I believe is a normal, successful exit. A small demo:


Like I said, I know next to nothing about windows specific programming so a second opinion on this method for exiting the AppGameKit app would be great.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 5th Jul 2012 23:00
heck yeah that works Hodgey,

I was looking at that loop but its kind of drowning me .. I have been teaching myself C++ since June 15th of this year so *everything* seems hard to me right now. Your analysis was more lucid than mine might have been thank you for taking the time to review it.

Now that menuing works I will start breaking some of these functions into separate files to keep the main program clean but this 'all in one' file helps understand how a menuing system *could work* case 5 is the quit game scenario and at least works well on Windows workstations.

My currently working code

Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 6th Jul 2012 04:15
Glad you got it working.

I'm currently teaching myself C and will then pick up C++. It's not a bad language but takes some time to adjust from BASIC. Have you started on pointers yet? They'll give you some fun.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 6th Jul 2012 15:50
Yeah I just finished the intro chapter on pointers on Tuesday of this week, and now working on arrays.

I can say I understand the idea of pointers.. That was expressed very clearly in the book I purchased but I definitely don't feel confident about their use in a practical sense yet. . Hopefully that comes with time and practice!
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 6th Jul 2012 16:01
Quote: "Hopefully that comes with time and practice!"

I'm getting the hang of them, but I'm sort of forcing myself to use them as much as possible, even when I don't need them, just to build up experience. Passing by reference seems to be quite handy.

Which book are you using?

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 6th Jul 2012 17:15
C Primer Plus 5th edition by Stephen Prata is the book I got. Actually got it as a kindle book so I can read it at any computer or even on my iPad which is working out nicely!

Login to post a reply

Server time is: 2024-04-25 06:43:02
Your offset time is: 2024-04-25 06:43:02