Canvas drawing/erase issue

Game Editor comments and discussion.

Canvas drawing/erase issue

Postby EvanAgain » Sat Jan 26, 2013 11:19 pm

On Mouse Enter of the Canvas it should erase.

On Mouse Enter of the Filled region it should move the wire frame then send activation event to Canvas to start a timer.

Timer(15ms) is up on Canvas draw wire frame to canvas.


THE PROBLEM:

It doesn't always erase, and it doesn't always draw in the proper place. I need a timer just to get it to come CLOSE to performing properly. I am unsure how to do this without an activation event.
Attachments
menus.ged
(4.38 KiB) Downloaded 124 times
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Canvas drawing/erase issue

Postby skydereign » Sat Jan 26, 2013 11:46 pm

Normally the timer should be unnecessary. Just put the code you have at the timer, into the activation event. The real problem is that you aren't being clone specific (which is why you see weird behaviour drawing). You should almost never access an actor's contents with actorname.variable if there are ever more than one of the actor. As for the not erasing, the problem is you are relying on mouse enter and mouse leave. I believe the mouse leave event requires the mouse to be on top of an actor with lesser zdepth (or no actor at all). That is why the pacman can hinder the erasing (higher zdepth, so the mouse leave event doesn't trigger).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Canvas drawing/erase issue

Postby EvanAgain » Sun Jan 27, 2013 12:07 am

The mouse enter is when the mouse hits the canvas itself it should erase, so there is room for the mouse to hit the canvas.

I don't want to use an activation event only because I can't specify the clones. I want it to be more automated. Another problem is all drawing seems to have to be done WITHIN canvas. So where I could put an if loop in the DRAW ACTOR section, or use a periodic timer to check to see if it should draw via global variable. I don't want it to have to be checking so frequently, only when the mouse hovers over the NON-Canvas actor.


How can I write functions for the Canvas? I supposed I couldn't because all draw functions need to be in the canvas.

Canvas would be extremely useful if I could use the functions OUTSIDE of the canvas itself.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Canvas drawing/erase issue

Postby skydereign » Sun Jan 27, 2013 12:13 am

EvanAgain wrote:Canvas would be extremely useful if I could use the functions OUTSIDE of the canvas itself.

Which is something I am looking into for future releases of gE. canvas also has the problem of not allowing canvas clones to work properly.

EvanAgain wrote:I don't want to use an activation event only because I can't specify the clones. I want it to be more automated.

Activation events doesn't mean you can't specify clones. In fact activation events are one of the greatest workarounds to problems in gE that deal with clones. Activation events are a powerful tool. There are ways of setting up your actors, and scripts, to be clone specific, while still having things automated.

EvanAgain wrote:How can I write functions for the Canvas? I supposed I couldn't because all draw functions need to be in the canvas.

You can write functions for canvas the same way you write a function for any other actor. The only catch is that only canvas actors would be able to call it properly. And the way to get an actor to call any function you want is through activation events.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Canvas drawing/erase issue

Postby EvanAgain » Sun Jan 27, 2013 12:25 am

skydereign wrote:
EvanAgain wrote:I don't want to use an activation event only because I can't specify the clones. I want it to be more automated.

Activation events doesn't mean you can't specify clones. In fact activation events are one of the greatest workarounds to problems in gE that deal with clones. Activation events are a powerful tool. There are ways of setting up your actors, and scripts, to be clone specific, while still having things automated.



Specifically..

How would I:

create a clone (in game) then
create an Activation event in the canvas linked to that clone (in game)




Also, I could say.. put this function Global code and then call it in the canvas?


Code: Select all
void canvasDrawSquare(int x, int y, int width, int height)
{
    moveto(x,y);
    lineto(x+width, y);
    lineto(x+width, y+height);
    lineto(x, y+height);
    lineto(x,y);
}
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Canvas drawing/erase issue

Postby skydereign » Sun Jan 27, 2013 12:36 am

SendActivationEvent takes a string. That string is a clonename. It doesn't have to be a literal string "actor.4", so you can use a char* or char array. So if you have a way of knowing which clone you want to send the event to (which index) then all you need to do is this.
Code: Select all
char buffer[30];
sprintf(buffer, "actor.%d", 4);
SendActivationEvent(buffer);

There are plenty of ways of figuring out what clone you want to send the event to do, and it usually depends on what you are trying to do and your overall set up. That's just part of setting up a good design. Now, in almost any sizeable project in gE I make, I include a global script along these lines.
Code: Select all
int activation_type = 0;
Actor* activator = NULL;

#define SOME_EVENT 1
#define OTHER_EVENT 2
#define CANVAS_EVENT 3

void
SendEvent (char* cname, int act_type)
{
    int t_activation_type = activation_type;
    Actor* t_activator = activator;

    activation_type = act_type;
    activator = getclone(clonename);
    SendActivationEvent(cname);

    activation_type = t_activation_event;
    activator = t_activator;
}

The SendEvent function sends an event to whichever clone you specify with clonename (you could have it where instead of a clonename, the function asks for a name, and an index, so it builds the clonename within the function). In this script I define a bunch of events with #define. All they represent is a unique number you can use to determine what is supposed to happen in the activation event.

EvanAgain wrote:Also, I could say.. put this function Global code and then call it in the canvas?

Just do this.
Code: Select all
SendEvent("canvas", CANVAS_EVENT); // changing canvas with a char* if you need to handle more than one canvas

That way in canvas' activation event, you can do this.
Code: Select all
switch(activation_type)
{
    case CANVAS_EVENT:
    canvasDrawSquare(x, y, width, height); // plugging in your wanted values of course
    break;
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Canvas drawing/erase issue

Postby EvanAgain » Sun Jan 27, 2013 1:40 am

The code you wrote is the reverse of what I am trying to do.

Let me try to explain a little clearer:


Activation Event Recipient: Canvas

Only one Canvas is used and activation events are sent to it from clones.
But from what I am understanding, activation events have to be tied to a pre-existing clone(sender).



Activation Event Senders: instanced Normal Actor clone (during play)

This newly created Actor clone would send the signal to the canvas to do something.



With what I am understanding there can only be 1 sender, but many recipients. I want the reverse of that, many senders and 1 recipient.


I am reading some code Hblade created with canvas to handle menu creation. I am trying to relatively the same thing except placing Actors on top of the canvas with minimal coding and draw_from.




To be specific about what I am trying to achieve:

Canvas background.
Vertical set of Actor Clones
On hover of Actor, draw square around Actor on the Canvas
On hover of next Vertical Actor "move" drawn square to This Actor
On Actor mouse click or keypress, create Actor Clone next to EventActor
Keep drawn square on "selected" actor, and draw a new square over any hovering actor.
Move only the hover square and keep the "selected" square drawn.
On selection of next tier of actors, draw new square on ALL clicked actors in tier.
On selection of new vertical Actor, delete all "tier" actors, and create new "tier" actors clearing canvas and redrawing new "Selected" square on vertical actor.
Repeat pattern.

+++++++++++++++

To do that it would seem that it would take storing and passing information through global variables. Not "too" big of a deal except that it requires the program to know and store extra information not otherwise necessary. The visual cues are only for the user and not needed by the program at all. So maybe my best option is to do away with the whole canvas and choose an different method all together. Possibly, just a small Actor to show "THIS IS SELECTED", "THIS IS HIGHLIGHTED"

I guess in writing this in a way I have answered my own problem. I just was really hoping to use the Canvas, but until the next update comes out, the canvas is almost "less than" useful for most things that are better suited for extra actors.

Thank you for you patience. But if you could just give me some feedback if you can gather what I am trying to convey. I am not very good at explaining. Unless, there is some way to send strict information with the least amount of calls, then an Actor would prove the most useful?
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Canvas drawing/erase issue

Postby skydereign » Sun Jan 27, 2013 1:58 am

EvanAgain wrote:But from what I am understanding, activation events have to be tied to a pre-existing clone(sender).

Not true. Are you trying to use gE's built in gui activation event mechanism? If so, don't. It is bad, and is very limiting. Any actor at any time can send an activation event to any other actor by using the SendActivationEvent. So, you can have many actors send activation events to the canvas.

EvanAgain wrote:With what I am understanding there can only be 1 sender, but many recipients. I want the reverse of that, many senders and 1 recipient.

Actually, if anything, you can only have one recipient. You can send the same event to multiple different actors, making it similar to having multiple recipients. But, each sender must call the SendActivationEvent, having one function to have multiple actors send the event wouldn't make sense.

EvanAgain wrote:To do that it would seem that it would take storing and passing information through global variables. Not "too" big of a deal except that it requires the program to know and store extra information not otherwise necessary.

gE doesn't provide a way of extending individual actors so eventually you need to create some system of referencing clones. This can be done with logic, actor variables, especial actor references, or with a global structure. It looks like from what you are building, that you might benefit from creating a struct to represent information for your gui. That being said, I think one could make what you listed, without using global variables. It just the code will probably turn out pretty hard to understand. With the SendEvent function I posted, you use two global variables (variables that should only be accessed within the SendEvent and actual activation event). With them though, you can send what action the actor should take, as well as a reference to the actor that sent the event.

EvanAgain wrote:the canvas is almost "less than" useful for most things that are better suited for extra actors.

If there is something that is better suited for what you want, use it. By default canvas is less than useful for things that have something that is better suited for it. The canvas actor can be very useful, and I believe it can be used for what you want. It does seem weird that you are mixing in a bunch of different actors into it, as it seems to just make it more complex.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Canvas drawing/erase issue

Postby EvanAgain » Sun Jan 27, 2013 2:20 am

skydereign wrote:
EvanAgain wrote:But from what I am understanding, activation events have to be tied to a pre-existing clone(sender).

Not true. Are you trying to use gE's built in gui activation event mechanism? If so, don't. It is bad, and is very limiting. Any actor at any time can send an activation event to any other actor by using the SendActivationEvent. So, you can have many actors send activation events to the canvas.



So? Don't use this?

For now, I think I will just go with using Actors. I am not quite sure how the whole Activation Events work. Even the code you wrote, I don't understand where the Recieving event even is, or how to create it, or how it works.
Attachments
ActivationEvent.JPG
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Canvas drawing/erase issue

Postby skydereign » Sun Jan 27, 2013 2:25 am

EvanAgain wrote:So? Don't use this?

No, it sounded like you were creating activation events from right clicking an actor, and selecting new activation event. I think I know what you mean now. I always set the from actor to Any Actor. That way any you aren't limited to pre-existing actors. And you use the SendEvent using different values, to determine what the actor should do.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Canvas drawing/erase issue

Postby EvanAgain » Sun Jan 27, 2013 3:06 am

That's actually how my code is set up, but still doesn't work.


I am attempting it now with actors and I can't get this piece of code to work, SO MANY ERRORS. I thought everything here was legal.


Code: Select all
char A_Highlighted[30]; // GLOBAL CODE

Actor* myActor;

if(doOnceTAH)
{
    myActor = CreateActor("text_Actor", "icon", "(none)", "(none)", -20, height/2, false);
    strcpy(A_Highlighted, myActor.clonename);
}

myActor = getclone(A_Highlighted);

strcpy(myActor.text, ">");
myActor.x = x - 20;
myActor.y = y + height/2;




OHHHH I understand now what you mean about the Actor obstruction. I Thought the actors were originally placed behind the Regions. I am going to try again with them behind and see if that makes a difference in the drawing.


EDIT:

While this one works exactly as intended, the issue being the actor was in front instead of behind and was never supposed to be that way. Also, it seems there are issues with parenting and those issues come about with the wireframe region. Unparenting the Actors then caused GE to crash, it was very strange.
Attachments
menus.ged
(4.95 KiB) Downloaded 124 times
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Canvas drawing/erase issue

Postby EvanAgain » Mon Jan 28, 2013 5:48 pm

I am going to figure out how to use that function you created because now I can understand it a little better and I now have an idea of actually how to implement it into my game.

Thank you!
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest