Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,238 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Small Tip: 1 img needed only to display a 3-state #100618
12/02/06 02:11
12/02/06 02:11
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Long time no posts from me here, sorry
Don't have free time (finishing my custom resource pack - write help files right now).
Well, small FREE contrib, or just the idea about game size minimizing (for small advert or other games that distributed over the internet). I think many of you use this, but forget to write about it.
In short - let's assume you have a project with many buttons for UI, you haven't to produce all 3 state images (on, off, over) to simulate a 'click' action on a button. You can process images by function ingame and reduce game size. You can use this technique not for buttons only, I think. And hey, c-scripters, all this stuff works without any plugin while you are learning C or C++!

Code:

bmap pan_map = "pan.tga";
bmap btn_map = "but.tga"; //look, all buttons are the same
bmap btnon_map = "but.tga";
bmap btnover_map = "but.tga";
bmap curs_map = "cursor.tga";
bmap pan_curs_map = "pancursor.tga";
font _font = "font.tga", 16, 23;

text hint = { //text over the panel
font = _font;
layer = 15;
pos_x = 15;
pos_y = 20;
size_y = 100;
offset_y = 0;
strings = 1;
flags = center_x, narrow, transparent, visible;
}

function test_on(btn_num,pnl){ //display button number
str_for_num(hint.string[0], btn_num);
}

panel _pan{ //simple 2 buttons panel
bmap = pan_map;
mouse_map = pan_curs_map;
layer = 10;
button = 40, 15, btnon_map, btn_map, btnover_map, test_on, NULL,NULL;
button = 150, 15, btnon_map, btn_map, btnover_map, test_on, NULL,NULL;
pos_x = 1; pos_y = 1; flags = VISIBLE,OVERLAY, REFRESH;
}

function mouse_startup // switches the mouse on
{
Mouse_Map = curs_map;
Mouse_Mode = 2;
while (1){
Mouse_Pos.X = Pointer.X;
Mouse_Pos.Y = Pointer.Y;
wait(1);
}
}

// This function is for example only,
// I didn't optimize it specially for clearness
// you can write a function to scroll, deform, hilight, etc.
bmap* tmp; //temp bitmap
function SimplifiedEmboss(Bitmap, Amount)
{
var format;
var x; var y; var i;
var p1; var p2; var p3;
var c1[3]; var c2[3]; var c3[3];
var a1; var a2; var a3;
tmp = Bitmap;
format=bmap_lock(tmp,0);
i = 0;
while (i <= Amount){
y = 0;
while(y <= bmap_height(tmp)-2){
x = 0;
while(x <= bmap_width(tmp)-2){
p1 = pixel_for_bmap(tmp, x, y); p2 = pixel_for_bmap(tmp, x, y + 1);
pixel_to_vec(c1, a1, format, p1); pixel_to_vec(c2, a2, format, p2);
c2.red = c2.red ^ -1;
c2.green = c2.green ^ -1;
c2.blue = c2.blue ^ -1;
vec_add(c1, c2);
c3 = c1 >> 1; a3 = (a1 + a2) / 2;
p3 = pixel_for_vec(c3, a3, format);
pixel_to_bmap(tmp, x, y, p3);
//additional passes
p1 = pixel_for_bmap(tmp, x + 1, y); p2 = pixel_for_bmap(tmp, x + 1, y + 1);
pixel_to_vec(c1, a1, format, p1); pixel_to_vec(c2, a2, format, p2);
c2.red = c2.red ^ -1;
c2.green = c2.green ^ -1;
c2.blue = c2.blue ^ -1;
vec_add(c1, c2);
c3 = c1 >> 1; a3 = (a1 + a2) / 2;
p3 = pixel_for_vec(c3,a3,format);
pixel_to_bmap(tmp, x + 1, y, p3);

p1 = pixel_for_bmap(tmp, x + 2, y); p2 = pixel_for_bmap(tmp, x + 2, y + 1);
pixel_to_vec(c1, a1, format, p1); pixel_to_vec(c2, a2, format, p2);
c2.red = c2.red ^ -1;
c2.green = c2.green ^ -1;
c2.blue = c2.blue ^ -1;
vec_add(c1, c2);
c3 = c1 >> 1; a3 = (a1 + a2) / 2;
p3=pixel_for_vec(c3,a3,format);
pixel_to_bmap(tmp, x + 2,y, p3);

x += 1;
}
y += 1;
}
i += 1;
}
bmap_unlock(tmp);
return;
}

function main() //your main function
{
max_loops = 200000; //you really need this, and don't try to process tons of full screen images ;)
SimplifiedEmboss(btnover_map,3); //create over and clicked states for buttons
SimplifiedEmboss(btnon_map,1);
level_load(level_load); //load level
wait(3);
mouse_tgl(); //show the mouse
}


I've used 32 bit tga with alpha channel for the button image.

Re: Small Tip: 1 img needed only to display a 3-state [Re: Lion_Ts] #100619
12/02/06 04:15
12/02/06 04:15
Joined: Sep 2002
Posts: 8,177
Netherlands
PHeMoX Offline
Senior Expert
PHeMoX  Offline
Senior Expert

Joined: Sep 2002
Posts: 8,177
Netherlands
Pretty nice contribution, perhaps this would be useful for skins with teamcolors too somehow? At the moment I've got no time to experiment with this code, but thanks for the contribution!

Cheers


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
Re: Small Tip: 1 img needed only to display a 3-state [Re: PHeMoX] #100620
12/02/06 08:24
12/02/06 08:24
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
this contribution is just the simple implementation of general idea. yes, you can make teamcolors, but not with this function actually. in my experiments i made teamcolors with materials and shaders, therefore, you may do it with skin manipulations by special function (to place a 'watermark' or a sign of your team over the base skin).


Moderated by  adoado, checkbutton, mk_1, Perro 

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