Page 1 of 1

MouseButtonDown on Canvas

PostPosted: Sat Feb 16, 2013 11:21 pm
by luckyshot29
hello, I'm creating a game where it can be resized using canvas. I followed lcl's resolutionary and it really helped me. I have a problem when it comes to having buttons in a Canvas, My game has a Solar System and the player needs to click a planet to go to that stage. Please help me with this one.

Re: MouseButtonDown on Canvas

PostPosted: Sat Feb 16, 2013 11:50 pm
by skydereign
Here's a function that is just a slight modification of how it draws things. The idea behind this, is it uses the xy coordinates that the draw function uses to draw to canvas, to compare if the xmouse/ymouse is within bounds of the scaled actor (currently using a box). One other modification I made to the loop is that it goes through the array backwards, so that actors that appear on top are clicked first.
Code: Select all
void clickActors()
{
    int i, j;
    Actor* centerActor = getclone(center);
    Actor * actors;
 
    actors = getAllActorsInCollision("Event Actor", &j);
 
    for (i = j-1; i >= 0; i --) // notice this goes backwards
    {
        if (strcmp(actors[i].clonename, center) != 0)
        {
            Actor* a = &actors[i];
            int xs = (view.width * 0.5 + ((a->x - centerActor->x) * size));
            int ys = (view.height * 0.5 + ((a->y - centerActor->y) * size));
 
            if(abs(xmouse-xs)<(a->width/2*size) && abs(ymouse-ys)<(a->height/2*size))
            {
                SendActivationEvent(a->clonename);
                return; // only click one actor, you can remove this if you want other actors underneath to be clicked
            }
        }
    }
}

So this uses SendActivationEvent as your mouse button down event. So just add the code you wanted in the mouse event to each of the actor's activation event.

Re: MouseButtonDown on Canvas

PostPosted: Sun Feb 17, 2013 12:14 am
by luckyshot29
Thank You very much Skydereign for your help! :) It solved my biggest problem. Now I can continue my project. Have a good day!

Re: MouseButtonDown on Canvas

PostPosted: Sun Feb 17, 2013 1:57 pm
by luckyshot29
I'm trying to add an Activation Event Button that needs to hold in order for my player actor to float, how can I do that?

Re: MouseButtonDown on Canvas

PostPosted: Sun Feb 17, 2013 7:05 pm
by skydereign
luckyshot29 wrote:I'm trying to add an Activation Event Button that needs to hold in order for my player actor to float, how can I do that?

What does that mean? An activation event button that needs to hold?

Re: MouseButtonDown on Canvas

PostPosted: Mon Feb 18, 2013 2:18 am
by moonforge
luckyshot29 wrote:I'm trying to add an Activation Event Button that needs to hold in order for my player actor to float, how can I do that?

I think what he means is that you need to hold down the mouse click to float.

If that is it, then you do
Mouse Button Down - (Float Code)
Mouse Button Up - (Stop Floating Code)
If you don't know how to make yourself float, just ask for more info.