select an entity with the mouse

Posted By: CItrok

select an entity with the mouse - 01/20/10 23:23

I need to select entities with the mouse. (for this exercise I need to display a message when selecting a entity, When I select an entity it is displayed "you clicked entity Nr.1! "

Anybody can suggest me? Thanks a lot.
Posted By: episch

Re: select an entity with the mouse - 01/21/10 00:00

try to usw de EVENT_CLICK ,EVENT_TOUCH events.
here is an example:


function click_event()
{
if(event_type == EVENT_CLICK)
{
show massage
}

action model()
{
my.emask |= ENABLE_CLICK;
my.event = click_event;
}

i hope i can help you
Posted By: CItrok

Re: select an entity with the mouse - 01/21/10 11:37

episch, thank you very much for your help. Unfortunately, I haven't succeeded.

Is not working by no means. WHAT is wrong in my code?

I uploaded the entire project files. I also let the code concerning with the joystick navigation, in order to assure this is not the problem.

I tried to modify "mouse_range" with differents values. The some thing, is not working.

http://uploading.com/files/bf432aa3/mouse_press.zip (you will have to wait about 50 seconds to download the zip archive )

Bellow is the code

#include <acknex.h>
#include <default.c>


STRING* aloha_str = "You clicked on earth!";

TEXT* greetings_txt =
{
pos_x = 300;
pos_y = 250;

string (aloha_str);
flags = SHOW;
}

function click_event()
{
if(event_type == EVENT_CLICK)
{
set(greetings_txt, SHOW);
}
}

action planet_act()
{

my.emask |= ENABLE_CLICK;
// my.enable_click = on;
my.event = click_event;
}


function main()
{
level_load("small.hmp");
ent_create("earth.mdl", vector(80, 80, 20), planet_act);
video_mode = 9;
mouse_range=400;
reset(greetings_txt, SHOW);
while(1)
{
camera.y -= joy_force.x;
camera.x += joy_force.y;
if (joy_4)camera.pan+=0.3;
if (joy_5)camera.pan-=0.3;
if (joy_1) camera.z += 1;
if (joy_2) camera.z -= 1;

if (joy_1 && joy_2)
{
camera.x = 0;
camera.y = 0;
camera.z = 0;
}
wait(1);
}


}



Thank you guys.
Posted By: Superku

Re: select an entity with the mouse - 01/21/10 13:14

You have to activate the gamestudio mouse by setting mouse_mode = 1 or 2, set mouse_pos and mouse_map (there is an example in the manual).
mouse_range=400; is a short range, btw.
Posted By: CItrok

Re: select an entity with the mouse - 01/21/10 20:37

thanks for the tip, Superku. I also added mouse_
pos.x = mouse_cursor.x; // allow the mouse pointer to move
mouse_pos.y = mouse_cursor.y; as you may see in the corrected code bellow:

So the code bellow is working...



#include <acknex.h>
#include <default.c>


STRING* aloha_str = "You clicked on earth!";

TEXT* greetings_txt =
{
pos_x = 300;
pos_y = 250;

string (aloha_str);
flags = SHOW;
}

function click_event()
{
if(event_type == EVENT_CLICK)
{
set(greetings_txt, SHOW);
}
}

action planet_act()
{

my.emask |= ENABLE_CLICK;
// my.enable_click = on;
my.event = click_event;
}


function main()
{
level_load("small.hmp");
ent_create("earth.mdl", vector(80, 80, 20), planet_act);
video_mode = 9;

mouse_mode = 2;

reset(greetings_txt, SHOW);
while(1)
{
camera.y -= joy_force.x;
camera.x += joy_force.y;
if (joy_4)camera.pan+=0.3;
if (joy_5)camera.pan-=0.3;
if (joy_1) camera.z += 1;
if (joy_2) camera.z -= 1;

if (joy_1 && joy_2)
{
camera.x = 0;
camera.y = 0;
camera.z = 0;
}

mouse_pos.x = mouse_cursor.x; // allow the mouse pointer to move
mouse_pos.y = mouse_cursor.y;


wait(1);
}


}
© 2024 lite-C Forums