Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (ozgur, degenerate_762, 7th_zorro), 1,081 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to make pulsating text? #270294
06/07/09 14:17
06/07/09 14:17
Joined: Jun 2009
Posts: 22
Finland
4gottenname Offline OP
Newbie
4gottenname  Offline OP
Newbie

Joined: Jun 2009
Posts: 22
Finland
Hey, I'm trying to recreate a old game and thougt I was starting out easy with making the start menu. On the first page there are 5 options (buttons): New Game, Load Game, Configuration, Credits and Exit Game. Problem is that the text on these buttons need to "pulsate" (grow bigger and then smaller over and over again). I've search the forums on how to animate buttons but didn't find any good anwser to that. Also it would requier too many bmaps so next I searched for a way to change the font size and came up with a very clumsy code. I'm using a TEXT* object called newgame_txt over a background panel with a trancparent button under the text. When you mouse over the button it calls a function that changes the font size in a while loop like this:
Code:
 function pulsate ()
{
	while(1) 
	{
		newgame_txt.font = size44_font;
		wait (-0.2);
		newgame_txt.font = size50_font;
		wait (-0.2);
		newgame_txt.font = size44_font;
		wait (-0.2);
		newgame_txt.font = size38_font;
		wait (-0.2);
		if (event_type == EVENT_RELEASE) { break; }
	}
}

The brake line don't work btw. It's suposed to stop pulsating when you move the pointer away from the button... (should do so without the brake line too...)

This code looks a bit uggly and long and I need to call it for every one of my buttons (there will be a lot of them on other "pages" and later in the game). So my questions is:
1. How do i make all the diffrent buttons to call a function that makes the text (for only the button that made the call) pulsate in a efficent way? I figured they need separate functions that hold a pointer to the right text and calls an other function that holds the pulsating code, but I don't know how to do that.
2. And how do I stop the loop when pointer no longer is over the button? If I change my code it will either pulsate forever or only one time. What am I missing?
Hope I explained it in a understandable way and that it has an easy solution wink


Last edited by 4gottenname; 06/07/09 16:51. Reason: I figured out how to center the text with CENTER_X and CENTER_Y so removed that from post. Earlier i had to set the x and y cord every time i changeg font size :P
Re: How to make pulsating text? [Re: 4gottenname] #270312
06/07/09 17:34
06/07/09 17:34
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
do you want to use text or can you create each option with bitmaps?

Re: How to make pulsating text? [Re: MrGuest] #270326
06/07/09 18:09
06/07/09 18:09
Joined: Jun 2009
Posts: 22
Finland
4gottenname Offline OP
Newbie
4gottenname  Offline OP
Newbie

Joined: Jun 2009
Posts: 22
Finland
Using text would be the best option since i need many of these pulsating text buttons. But if you know how to make animated bmap buttons, please tell smile could come in handy in other projects

Re: How to make pulsating text? [Re: 4gottenname] #270329
06/07/09 18:20
06/07/09 18:20
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
the way i did it with bmaps is to have them all as seperate panels, then use mouse_panel to determine if the mouse is still over the panel

store a panel pointer as active_panel

then check at the start of the function for the mouse_over if(active_panel)
if true then set this back to it's default values
active_panel.scale_x = 1 etc...

then set the new panel as the active_panel... and manipulate as you want to

Code:
while(1){

  if(active_panel){
    while(active_panel.scale_x < 1.5){
      if(active_panel == mouse_panel){
        active_panel.scale_x += 0.05;
        wait(1);
      }
    }

    while(active_panel.scale_x > 0.5){
      if(active_panel == mouse_panel){
        active_panel.scale_x -= 0.05;
        wait(1);
      }
    }
  
    wait(1);
  }else{

    wait(1);
//    loop function

}[code]

alternaltively if you want to use textsizes
store the ones you need in an array

[code]FONT* fnt_pulse[5];
  then use similar code for cycling thro the fonts


hope this helps
*untested*

Re: How to make pulsating text? [Re: MrGuest] #270341
06/07/09 19:33
06/07/09 19:33
Joined: Jun 2009
Posts: 22
Finland
4gottenname Offline OP
Newbie
4gottenname  Offline OP
Newbie

Joined: Jun 2009
Posts: 22
Finland
Wow, thanx Mister! smile Looks a bit too complicated for me to understand atm, but will try it out and study it the coming days. Realy need to figure out how those pointers work...

Re: How to make pulsating text? [Re: 4gottenname] #271402
06/12/09 22:02
06/12/09 22:02
Joined: Jun 2009
Posts: 22
Finland
4gottenname Offline OP
Newbie
4gottenname  Offline OP
Newbie

Joined: Jun 2009
Posts: 22
Finland
I'm still struggling with this pulsating text thing. I didn't get MrGuests code to work and I realy would prefer TEXT instead of bmaps. Here is the code I got so far:
Code:
 ///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
//BMAP* backgroundpergament_tga = "backgroundpergament.jpg"; // background image 800x600
BMAP* transparentbutton_pcx = "transparentbutton.pcx"; // 210x40
FONT* normal38_font = "Arial#38"; // was using a cooler font here
FONT* medium44_font = "Arial#44"; // but it's uncommon so changed
FONT* large50_font = "Arial#50";  // it to standard boring arial...
TEXT* pulsatingtextpointer = NULL;
////////////////////////////////////////// START ///////////////////////////////////////
PANEL* start_panel = // the first panel. will show at game start up
{
	layer = 1; 
//	bmap = backgroundpergament_tga;
	flags = OVERLAY | SHOW;
	button (295, 250, transparentbutton_pcx, transparentbutton_pcx, transparentbutton_pcx, NULL, normalfont, newgame_puls);
	button (295, 290, transparentbutton_pcx, transparentbutton_pcx, transparentbutton_pcx, NULL, normalfont, loadgame_puls);
	button (295, 330, transparentbutton_pcx, transparentbutton_pcx, transparentbutton_pcx, NULL, normalfont, options_puls);
//	button (295, 370, transparentbutton_pcx, transparentbutton_pcx, transparentbutton_pcx, NULL, normalfont, credits_puls);
//	button (295, 410, transparentbutton_pcx, transparentbutton_pcx, transparentbutton_pcx, NULL, normalfont, quitgame_puls);

}
TEXT* pulsatingtextpointer2 =
{
	font = normal38_font;
}
TEXT* newgame_txt =
{
	pos_x = 400;
	pos_y = 250;
	layer = 2;
	font = normal38_font;
	red = 255;
	green = 255;
	blue = 190;
	string = "New Game";
	flags = CENTER_X | CENTER_Y | SHADOW | SHOW;
}
TEXT* loadgame_txt =
{
	pos_x = 400;
	pos_y = 290;
	layer = 2;
	font = normal38_font;
	red = 255;
	green = 255;
	blue = 190;
	string = "Load a Game";
	flags = CENTER_X | CENTER_Y | SHADOW | SHOW;
}
TEXT* options_txt =
{
	pos_x = 400;
	pos_y = 330;
	layer = 2;
	font = normal38_font;
	red = 255;
	green = 255;
	blue = 190;
	string = "Configuration";
	flags = CENTER_X | CENTER_Y | SHADOW | SHOW;
}
////////////////////////// FUNCTION MAIN /////////////////////////////////
function main()
{
	video_mode = 7; // 800x600
	mouse_mode = 1;
	wait (1);
	while (1)
   {
      mouse_pos.x = mouse_cursor.x; // need these to move the cursor
      mouse_pos.y = mouse_cursor.y;
      wait (1); 
   }
}
//////////////////////////////////////////////////////////////////////////
function normalfont ()
{
	pulsatingtextpointer2 = pulsatingtextpointer;
	pulsatingtextpointer2.font = normal38_font;
	wait (1);
}
function pulsate ()
{
	while (mouse_calm) // while pointer over button
		{
			pulsatingtextpointer.font = medium44_font;
			wait (-0.2);
			pulsatingtextpointer.font = large50_font;
			wait (-0.2);
			pulsatingtextpointer.font = medium44_font;
			wait (-0.2);
			pulsatingtextpointer.font = normal38_font;
			wait (-0.2);
			if (mouse_moving) { break; } 		
			
		}
		wait(1);
}

function newgame_puls()
{
	pulsatingtextpointer = newgame_txt;
 	pulsate();
}
function loadgame_puls()
{
	pulsatingtextpointer = loadgame_txt;
 	pulsate();
}
function options_puls()
{
	pulsatingtextpointer = options_txt;
 	pulsate();
}


I'm using a black (all pixels RGB = 000) pcx image size: 210x40 under all the text lines. You need to make one if you want to try this script and see what Im after.
If you slowly move the mouse over a button the text will pulsate the way I want, but if you move fast over all the buttons things will get messy frown

I need a better argument for the while() and brake line in the pulsate function. And limit the function to only be run one at a time. I've searched the manual for usefull commands but not found suitable ones for this or not figured out how to use them properly. I want the pulsate code to run while the mouse is over the button and stop when you move away from it. My current brake line with mouse_moving makes it stop when you move a bit to the side so not good enough.

The normalfont function is called when you move the mouse pointer away from a button and is suposed to reset the font back to the normal size. Might be too slow since it don't work when you move fast? Maybe need to add something that stops the pulsating and waits a bit before leting the next button/text pulsate...

Would be nice to skip all the diffrent mouse over functions and call the pulsate directly from the button lines and give it the right text pointer too. Is that possible? The thing I tried gave a error with too many arguments...

Please read my first post also If its unclear what I'm trying to do and keep in mind that I'm a beginner with programming so give easy understood advices if you have some, thx smile

Re: How to make pulsating text? [Re: 4gottenname] #271405
06/12/09 23:02
06/12/09 23:02
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try this variation.
If you need to make changes, or want to know "why?", "how?" or even "WTF?!!?!",
then just ask.
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
//BMAP* backgroundpergament_tga = "backgroundpergament.jpg"; // background image 800x600
BMAP* transparentbutton = "#210x40x32";		//create temporary black image for button
FONT* normal38_font = "Arial#38"; // was using a cooler font here
FONT* medium44_font = "Arial#44"; // but it's uncommon so changed
FONT* large50_font = "Arial#50";  // it to standard boring arial...
////////////////////////////////////////// START ///////////////////////////////////////
PANEL* start_panel = // the first panel. will show at game start up
{
	layer = 1; 
	pos_x = 295;	pos_y  = 250;
	size_x = 210;	size_y = 440;
	button (0, 0  , transparentbutton, NULL, NULL, NULL, NULL, pulsate_text);
	button (0, 40 , transparentbutton, NULL, NULL, NULL, NULL, pulsate_text);
	button (0, 80 , transparentbutton, NULL, NULL, NULL, NULL, pulsate_text);
//	button (0, 120, transparentbutton, NULL, NULL, NULL, NULL, pulsate_text);
//	button (0, 160, transparentbutton, NULL, NULL, NULL, NULL, pulsate_text);
	flags = OVERLAY | SHOW;
}
TEXT* pulsatingtextpointer2 =
{
	font = normal38_font;
}
TEXT* newgame_txt =
{
	pos_x = 400;	pos_y = 250;
	layer = 2;		font = normal38_font;
	red = 255;		green = 255;		blue = 190;
	string = "New Game";
	flags = CENTER_X | CENTER_Y | SHADOW | SHOW;
}
TEXT* loadgame_txt =
{
	pos_x = 400;	pos_y = 290;
	layer = 2;		font = normal38_font;
	red = 255;		green = 255;		blue = 190;
	string = "Load a Game";
	flags = CENTER_X | CENTER_Y | SHADOW | SHOW;
}
TEXT* options_txt =
{
	pos_x = 400;	pos_y = 330;
	layer = 2;		font = normal38_font;
	red = 255;		green = 255;		blue = 190;
	string = "Configuration";
	flags = CENTER_X | CENTER_Y | SHADOW | SHOW;
}
////////////////////////// FUNCTION MAIN /////////////////////////////////
function main()
{
	video_mode = 7; // 800x600
	mouse_mode = 1;
	wait (1);
	while (1)
   {
      mouse_pos.x = mouse_cursor.x; // need these to move the cursor
      mouse_pos.y = mouse_cursor.y;
      wait (1); 
   }
}
//////////////////////////////////////////////////////////////////////////


function pulsate_text(var butt_over, PANEL* this_pan)
{
	proc_kill(4);
	newgame_txt.font = normal38_font;
	loadgame_txt.font = normal38_font;
	options_txt.font = normal38_font;
	wait(1);
	//
	TEXT* this_text;
	switch(butt_over)
	{	
		case 1:		this_text = newgame_txt;
		case 2:		this_text = loadgame_txt;
		case 3:		this_text = options_txt;
	}	
	//
	while(1)
	{
		this_text.font = medium44_font;
		wait (-0.2);
		if(mouse_panel!=this_pan)	break;
		this_text.font = large50_font;
		wait (-0.2);
		if(mouse_panel!=this_pan)	break;
		this_text.font = medium44_font;
		wait (-0.2);
		if(mouse_panel!=this_pan)	break;
		this_text.font = normal38_font;
		wait (-0.2);
		if(mouse_panel!=this_pan)	break;
	}
	newgame_txt.font = normal38_font;
	loadgame_txt.font = normal38_font;
	options_txt.font = normal38_font;
}



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How to make pulsating text? [Re: EvilSOB] #271466
06/13/09 11:09
06/13/09 11:09
Joined: Jun 2009
Posts: 22
Finland
4gottenname Offline OP
Newbie
4gottenname  Offline OP
Newbie

Joined: Jun 2009
Posts: 22
Finland
This works perfectly! Thank you so much for taking the time to help me out laugh
I had to change my buttons panel size to only fit the buttons, before it was fullscreen background so the panel was always active and one of the texts kept pulsating.

"#210x40x32" <-- thats a intressting way to create bmaps. (Is it possible to set RGB value for it?) Could use them to make the diffrent buttons fit the diffrent text lenghts better but would need the pulsating code to react to the button bmap instead of the panel, or make all buttons as individual panels. Then the question would be how to change this_pan...?
Gona be about 30 pulsating text/buttons, spread out over diffrent "pages" and not always close to each other. And thats for start panels only... more later in the game... shocked

Some new things for me in the code...
proc_kill(4); found this in the manual before, didn't understand how to use it. Is it realy enough with that one line? blush
The switch and its cases... "If it matches any of the case values, the instructions following the colon are executed" ok... so it's sorta like a if comparison? but easyer to add more stuff in...?

Pointers are still very confusing for me. Are this_pan and this_text made up pointers? How do the engine know what we'r after? I can't see any line of code that checks for where the mouse pointer is exept for in the:
if(mouse_panel!=this_pan) break; (smart to put in the brake after all font changes, why didn't I think of that...)
How is this_text set and changed? In the switch case? What's the butt_over var then...? Would make more sence if they where predefined commands but since they'r not found in the Lite-C manual they would have to be from C-script or C/C++...maybe?
So many questions... smile

Re: How to make pulsating text? [Re: 4gottenname] #271494
06/13/09 13:42
06/13/09 13:42
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
"#210x40x32" will only create pure black maps, but you could create a few and put a
bmap_fill() on some of them with different colors at the start of main to change their color.

[EDIT] Not so simple with BMAPs used by global panel definitions.


... how to make my code react to just the buttons, not the panel itself...
Hmmmm. Let me think on that, it may be do-able.

30 separate panels? I aint going to think about that at ALL!

Proc_kill(4) kills all OTHER copies of itself current running, so only itself remains.
And "this" itself then resets the sizes of ALL the texts, thats really is enough.

Switch is a beautiful little command.
Think of it like this. It is a string of IF's, as it goes through the string,
EVERY time the CASE is a match, this little block of code executes. Then it checks the next one.
Its JUST like a group of IF's you say? But WHOA, just execute one BREAK; from anywhere in there,
and it skips the REST of the CASE's and jumps out of the whole SWITCH block. COOL!
AND, if you put the "case default:" in there, it will run this block every time,
even if NONE if the other CASE's were true.
It WILL run as long as none of the other cases executed a 'break;' command anyway.

this_text is a pointer I made up, and my switch block just "aims" the pointer at the real TEXT object
that "belongs" to that button number, which is stored into butt_over.
Now comes the tricky part.
BOTH butt_over and this_pan you will see in the "pulsate_text" parameter list,
thats where they are coming from.
"But we didnt say to send them in the button!" I hear you say. True, we didnt.
But if you look carfully through the "Button" entry in the manual, you'll find this
Several buttons may share the same function. The number of the button is
passed as the first parameter to the function (1 = first button), the panel
pointer is passed as the second parameter.

Thats how they got sent, so look at my parameter list, and you can see how to use them.

"this_text" is SET in my switch command. thats the only time it gets set in any way.
"this_text" is just a pointer, not a "real" object, and lite-c knows this.
So when we say this_text.font = large50_font;, then lite-c says
"I cant change this_text's font, cause its not an object. BUT it is POINTING
at a real TEXT object, so I'll change the font of THAT object instead!"
This is an easy way to think of pointers. They USUALLY get used this way.

Make "more" sense yet?
Feel free to ask more if you want.

PS Welcome aboard, if I havent already said so...


Last edited by EvilSOB; 06/14/09 02:07. Reason: Corrected faulty assumption

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How to make pulsating text? [Re: EvilSOB] #271509
06/13/09 15:44
06/13/09 15:44
Joined: Jun 2009
Posts: 22
Finland
4gottenname Offline OP
Newbie
4gottenname  Offline OP
Newbie

Joined: Jun 2009
Posts: 22
Finland
Now THAT'S a good explanation! grin
Now I understand most if not all. Will read thru a few more times, just to be sure...
Pure black bmaps is enough, but could use filled ones to check that they realy are at right places.
Hehe, not asking you to do all my panel/buttons, need to do some work myself wink
I can use a few other functions with the same code in it, one for each "page" to keep them in order. But if there's a way to get the pulsating to run only while over a button I could use a full screen panel with buttons spread out all over the screen, not just thight together.
I did see the "Button entry in the manual" and thought I could use it to detect if mouse pointer still on a sertain button in my previous scripts but again, did not know how to make it work. Manual could use more exampels and beter explanations imo... :p
Thank you so much again! And no need to think too much about the code reacting to just the buttons not panel if it gets too complicated, the code you already given is more then enough for me to work with smile

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1