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.

Dark GDK / Using Sprites for buttons

Author
Message
Night
15
Years of Service
User Offline
Joined: 3rd Jan 2009
Location:
Posted: 4th Jan 2009 01:26
Ive searched around the forums and found that in DBPro they use sprite and sprite collision to do buttons but seems that the prominent method for GDK was to just use location. So i tried to make it with sprites and got it to work but was wondering why it seemed nobody was using this method or if there was a better way to do it besides this:
Night
15
Years of Service
User Offline
Joined: 3rd Jan 2009
Location:
Posted: 4th Jan 2009 02:10
another thing I forgot to mention/ask was how i would go about checking for when the button is released, would i need to assign a variable for that of is there a different way.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 4th Jan 2009 03:12
Seriously - who cares - if its working for you (which BTW I personally like your concise style) - Use it!

I used coordinates my self but only cuz I have multiple controls on a given "sprite".. I made each sprite a window form...

--Jason

Night
15
Years of Service
User Offline
Joined: 3rd Jan 2009
Location:
Posted: 4th Jan 2009 03:27
Well really i was more wondering if there was a reason why and if there was a negative side to this. Like if moving a tiny sprite around with the mouse was a bad idea but i guess if your checking the coords of the mouse every time also there would be that problem as well. I guess the coords would be nicer for making forms cause you could do it with one sprite instead of a whole bunch.

I just like to get input on whats more effective and efficient so that i learn things the best way and dont have to relearn a better way later
tehg00n
15
Years of Service
User Offline
Joined: 4th Jan 2009
Location: Ohio
Posted: 4th Jan 2009 16:51
What I used to do was create a "LoadButton" and "SpriteButton" function in a buttonhandler class.

In the LoadButton just make the coordinates of each corner some of the parameters. Then the SpriteButton will use dbSprite and automatically check for clicking.

All what Jason P Sage was saying, but that is just how I cleaned it up for efficiency. That way your not looking directly at a bunch of coordinates and confusing logic.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Jan 2009 18:33
Whatever works for you is fine. My personal take is use OO. But this pretty much requires building your entire coding around the concept. For me this involves a lot of up front coding of the classes but reduces the amount of coding when applied to subsequent projects.

I have a Mouse class that's designed as a singleton. So no matter where I create a Mouse object it's always using the data from any other Mouse object. My Sprite class has a method for detecting if the cursor is over it.

Unfortunately my motherboard went south on New Years Eve and I had to replace the board, the processor and the video card in addition to installing two terabytes of storage. I haven't re-installed my DGDK components or the VS C# Express yet so I can't look things up to see how I specifically designed things but my code for detecting if a button was clicked might look something like this



This kind of structure could be used to check several buttons that might be available within the game context at the time. It eliminates complications when having to check for multiple buttons. Something similar could be accomplished using a procedural function that returns the number of a pressed button.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 4th Jan 2009 20:12
I still have the first runs of those classes if you need them Lilith - (she has good code in there!)

Sorry bout the PC woes - that REALLY stinks.

P.S. Happy New Year to ya!
--Jason

Night
15
Years of Service
User Offline
Joined: 3rd Jan 2009
Location:
Posted: 4th Jan 2009 20:22
Yeah I actually stumbled upon one of your post with your mouse object and was looking at that its a little above my c++ level still learning the different terminology, Ill have to continue looking at that and figure out what i want to do in the end, but thanks for the inputs
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Jan 2009 22:03
Quote: "I still have the first runs of those classes if you need them Lilith "


I still have the source code, so it's no problem. I just haven't set up the compiling software and I wasn't ready to use notepad to look through the header files. I seriously need to look at finding a spot to put this stuff online. The only thing that has stopped me from doing so has been a lack of time to complete testing, which may be impossible. The primary lack was in getting the animated sprite to work properly and that may just be a matter of me not understanding how it really worked. I may just have to tweak it a bit and it should be ready.

And Happy New Year to you too, BTW.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Quadrazar
15
Years of Service
User Offline
Joined: 7th Jan 2009
Location: onboard the Kobayashi Maru
Posted: 14th Jan 2009 19:38 Edited at: 15th Jan 2009 05:12
Alternative sprite buttons:

a possible alternative to sprite collisions is the use of a spriteIdBitmap.

components.
- a spritebuttonClass
--> a virtual base class for buttons
- a spriteVector
--> a vector containing all sprite buttons created. ( vector<spriteButton*> buttonlist; ) .
- a spriteMap
--> a memoryblock the same size as the screen. ( int size, int height, int data). (links a screen coordinate to a index in the vector<> )

- a mouse function or class called inside the game loop.
As soon as a button sprite is placed on the screen the spriteMap is altered. The region filled on the screen by the button sprite is 'coloured in' on the sprite map with an integer equal value to the spritebuttons index in the spritelist vector;

the major pro to this system is that you can use the alpha values of the pixels. This enables a form of masking.

I've been trying to work it out and it's going fine, only thing. My sprites starts to flicker when I go over it with the mouse. I guess I'll have to review my sprite knowledege. For now Here is the code so far.

preproccesor.h


spritebutton.h


spritebutton.cpp



cursor.h


cursor.cpp


main.cpp
Kilrath
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Alberta
Posted: 3rd Feb 2009 04:07
maybe i suck at this but i use:


Saving the world, one bit at a time.... Wait it's not worth saving. Get your own bits!

Login to post a reply

Server time is: 2024-09-30 15:20:52
Your offset time is: 2024-09-30 15:20:52