Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (blaurock), 750 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Creating A Grid #316169
03/22/10 03:00
03/22/10 03:00
Joined: Dec 2009
Posts: 6
N
nikka08 Offline OP
Newbie
nikka08  Offline OP
Newbie
N

Joined: Dec 2009
Posts: 6
Hi all. I'm trying to create a loop to generate a 2D 32*32 grid across the 1024*768 screen. In each cell, I would like a PANEL.

I tried using a couple simple array variables, but I came up with a few problems.

1) Can a panel be created within a while() loop using a name based on the array variable? i.e.-PANEL* Grid(1); PANEL* Grid(2)...

2) I seem to be having a problem using:
PANEL* Grid(1) =
{pos_x = grid_x[1]; pos_y = grid_y[1]}
It keeps giving me a syntax error on the "pos_x = grid_x[1];" line.

Basically, I'm trying to have a loop do the following:

Panel at 0,0
Panel at 0,32
Panel at 0,64....etc.

I seem to be going about it from the wrong direction, could someone please help me?

Re: Creating A Grid [Re: nikka08] #316170
03/22/10 03:08
03/22/10 03:08
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
1) When creating panels in a function, you have to use the function 'pan_create'. Panel* definitions can only be declared globally.

2) Like point 1, you have to use 'pan_create' function when building a panel at runtime. Also you can only pass constants to certain members of a panel definition.

Re: Creating A Grid [Re: DJBMASTER] #316171
03/22/10 03:13
03/22/10 03:13
Joined: Dec 2009
Posts: 6
N
nikka08 Offline OP
Newbie
nikka08  Offline OP
Newbie
N

Joined: Dec 2009
Posts: 6
Originally Posted By: DJBMASTER
1) When creating panels in a function, you have to use the function 'pan_create'. Panel* definitions can only be declared globally.


Ok, so I'm using the pan_create function instead of PANEL*.

Originally Posted By: DJBMASTER
2) Like point 1, you have to use 'pan_create' function when building a panel at runtime. Also you can only pass constants to certain members of a panel definition.


So are you saying that I can't use an array to define the position of the panel?

Thank you very much for your quick response.

Re: Creating A Grid [Re: nikka08] #316173
03/22/10 04:07
03/22/10 04:07
Joined: Oct 2009
Posts: 110
Porto-Portugal
Elektron Offline
Member
Elektron  Offline
Member

Joined: Oct 2009
Posts: 110
Porto-Portugal
I think you can use array but it must be global.

I hope it helps


Carlos Ribeiro aka Elektron
Check my blog: http://indiegamedeveloper71.wordpress.com/
Re: Creating A Grid [Re: Elektron] #316179
03/22/10 06:29
03/22/10 06:29
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Sure you can use an array to define the position. You have 2 choices...

1) If you know the positions already use a global array.
2) If you want to calculate positions and store them in an array, you will need to know how to use 'dynamic memory', with the functions 'malloc/calloc/free'.

Re: Creating A Grid [Re: DJBMASTER] #316347
03/23/10 14:56
03/23/10 14:56
Joined: Dec 2009
Posts: 6
N
nikka08 Offline OP
Newbie
nikka08  Offline OP
Newbie
N

Joined: Dec 2009
Posts: 6
Originally Posted By: DJBMASTER
Sure you can use an array to define the position. You have 2 choices...

1) If you know the positions already use a global array.
2) If you want to calculate positions and store them in an array, you will need to know how to use 'dynamic memory', with the functions 'malloc/calloc/free'.


I am using a global array that I defined all of the positions for. My problem is the actual syntax of the code. Instead of pos_x = 256;, I used pos_x = Gridx[8];. And it errors. So I guess I'm just asking how you would actually code it. Again, thank you for your responses.

Re: Creating A Grid [Re: nikka08] #316354
03/23/10 15:31
03/23/10 15:31
Joined: Nov 2009
Posts: 89
Germany, NRW
T
TrackingKeks Offline
Junior Member
TrackingKeks  Offline
Junior Member
T

Joined: Nov 2009
Posts: 89
Germany, NRW
You have to set the position in a loop,not in the panel definition to define the position. I think you have to use pan_setpos.

Last edited by TrackingKeks; 03/23/10 15:33.

Gamestudio: A7.82 Commercial/A8 Commercial
System specs (Laptop):
Windows 7 64bit
DirectX v10.1
Intel Core i7-720QM CPU @ 1,60 GHz
4GB DDR2 Ram
NVIDIA GeForce GT 230M (1024MB)
Re: Creating A Grid [Re: TrackingKeks] #316376
03/23/10 16:59
03/23/10 16:59
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Yes, you can't specify variables in the panel definition. They can only be changed within a function. There's no need for 'pan_setpos' because you can directly modify the positon with 'PANEL*.pos_x/pos_y'...
Code:
var gridx[5] = {0,32,64,96,128};
var gridy[5] = {0,32,64,96,128}; // bla bla
BMAP* panel_bmap = "image.bmp";

void CreateGrid()
{
PANEL* p = pan_create("",1);
p.bmap = panel_bmap;
p.pos_x = gridx[0]; p.pos_y = gridy[0];
set(p,SHOW);
}


Of course, this is tedious, so let the computer do the work...
Code:
BMAP* bmp = "image.bmp";

void CreateGrid()
{
var i,j,size = 33; // tested with a 32x32 picture.

for(i=0; i<screen_size.x; i+=size)
{
	for(j=0; j<screen_size.y; j+=size)
	{
	PANEL* p = pan_create("",1);
	p.bmap = bmp;
	p.pos_x = i; p.pos_y = j;
	set(p,SHOW);
	}
}

}



Re: Creating A Grid [Re: DJBMASTER] #316419
03/23/10 23:35
03/23/10 23:35
Joined: Dec 2009
Posts: 6
N
nikka08 Offline OP
Newbie
nikka08  Offline OP
Newbie
N

Joined: Dec 2009
Posts: 6
Ok, I get it now, thank you so, so much, djbmaster. Your help is very much appreciated.


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