Wie kann man eine View Entity anklicken?

Posted By: ColeFoster

Wie kann man eine View Entity anklicken? - 11/05/23 19:26

Hallo zusammen, ich habe noch die gamestudio A7 und möchte ein 2d Adventure mittels wed kreieren. Ich benutze als Räume eine TGA Grafik als view Entity. Soweit so gut. Nun möchte ich eine zweite View entity mit einem höheren Layer als anclickbares Objekt darüber legen wie z. B. Eine Tür oder Gegenstand. Das geht auch das Problem dabei ist, dass die art von Entity nicht anklickbar ist. Ich habe versucht über eine Funktion enable click und dann dass event dazu zu schreiben. Es gibt keine Fehlermeldung aber beim anklicken tut sich einfach nichts.
Bin gespannt ob es dafür eine Lösung gibt. Danke schon einmal im voraus.
Posted By: rayp

Re: Wie kann man eine View Entity anklicken? - 11/06/23 19:21

Hallo.
Ich persönlich würde Dir von view ents abraten.

So weit ich weiss ist bei view ents auch die XYZ Position Auflösungsabhängig.
Ich benutze aber nie View ents muss ich dazu sagen, weiss aber das die sich nicht so einfach anklicken lassen.

Ich würde Dir empfehlen das ohne View ents aufzubauen.
Dann bist Du auch nicht von der Auflösung abhängig und hast meiner Meinung nach nur Vorteile.

Ich habe Dir hier ein Beispiel verfasst wie Du das gleiche ohne View ents bauen könntest:
Code
// example needs:
// backgr1.tga = 1024x768 background image
// backgr2.tga = same
// door1.tga   = a door image
// door2.tga   = same
// cursor.tga  = mouse cursor
BMAP* bmap_arrow = "cursor.tga"; // mouse cursor bitmap

ENTITY* your_background;         // pointer to your used background image 1024x768 in this example
ENTITY* your_door_ent;           // pointer to your door image (any size)


void your_background_ent_event_1(){ // first example event for your background
   if (event_type == EVENT_CLICK){
      printf ("You clicked the background");
   }			
}
void your_background_ent_event_2(){ // second example event for your background room 2
   if (event_type == EVENT_CLICK){
      printf ("You clicked the background in room2");
   }			
}


void your_door_ent_event_1(){      // first example event for your door
   if (event_type == EVENT_CLICK){
      printf ("You clicked the door entity");
   }			
}
void your_door_ent_event_2(){      // second example event for your door in room2
   if (event_type == EVENT_CLICK){
      printf ("You clicked the door entity in room2");
   }			
}

// load the background and the door and give them click events
void init_level_screen1(){
   your_background = ent_create ("backgr1.tga", vector (880,0,0), NULL); // 1024x768 background image for example fills screen at this position
   if (your_background){
      your_background.emask |= ENABLE_CLICK;
      your_background.event = your_background_ent_event_1;
   }	
   your_door_ent = ent_create ("door1.tga", vector (879,0,0), NULL); // in front of the background image
   if (your_door_ent){
      your_door_ent.emask |= ENABLE_CLICK;  
      your_door_ent.event = your_door_ent_event_1;	     
   }
} 

// example how you could switch to another room
void init_next_room (roomnr){
    if (roomnr == 2){
       if (your_background){
          ent_morph (your_background, "backgr2.tga");		
	  your_background.event = your_background_ent_event_2;
      }
      if (your_door_ent){
         //your_door_ent.y = 100;
         //your_door_ent.z = 50;
         ent_morph (your_door_ent, "door2.tga");		
         your_door_ent.event = your_door_ent_event_2;
      }
   }
}

var room_active = 1;

// press enter to switch to room nr2 for example
void main(){ 
   video_mode = 7;
   video_screen = 2;
   level_load (NULL); // or a empty wmb file
  
   init_level_screen1();
    
   mouse_map = bmap_arrow;  
   mouse_mode = 4;       
  
   while (1){
      if (key_enter){
         if (room_active == 1){
            room_active += 1;
            init_next_room (room_active); //change background and the door image for next room now           
         }
      }	
      wait (1);
   }
}

Das Beispiel lädt eine Hintergrundgrafik und platziert eine Türgrafik darauf. Mit der Enter Taste kannst Du in den zweiten Raum wechseln.

Das script als main.c speichern und ausführen. backgr1.tga(1024x768), backgr2.tga, door1.tga, door2.tga und cursor.tga dazu.
Wenn Du für die Backgrounds eine andere Auflösung willst als 1024x768, musst Du einfach nur den X Wert (880) anpassen, solange bis das Image das Fenster wieder füllt.

Das Beispiel ermöglicht nun auch scrollen (z.B. per camera.yz) oder zoomen (z.B. per camera.arc oder camera.x).
Posted By: ColeFoster

Re: Wie kann man eine View Entity anklicken? - 11/07/23 16:52

Hallo, danke für die Antwort.
Nein bei View Entitys sind die xyz Positionen nicht Auflösungsabhängig und behalten auch ihre Größe bei.

Void habe ich noch nie etwas gemacht, denke aber das es ein guter Weg ist den du mir da geschrieben hast.Werde ich auf jeden Fall mal ausprobieren.
Posted By: rayp

Re: Wie kann man eine View Entity anklicken? - 11/07/23 18:05

Anstelle von void kannst Du auch function schreiben.
© 2024 lite-C Forums