MouseButtonDown on Canvas

Non-platform specific questions.

MouseButtonDown on Canvas

Postby luckyshot29 » Sat Feb 16, 2013 11:21 pm

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.
Attachments
canvasclick.rar
(1.92 MiB) Downloaded 97 times
luckyshot29
 
Posts: 6
Joined: Sat Feb 02, 2013 7:38 pm
Score: 0 Give a positive score

Re: MouseButtonDown on Canvas

Postby skydereign » Sat Feb 16, 2013 11:50 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: MouseButtonDown on Canvas

Postby luckyshot29 » Sun Feb 17, 2013 12:14 am

Thank You very much Skydereign for your help! :) It solved my biggest problem. Now I can continue my project. Have a good day!
luckyshot29
 
Posts: 6
Joined: Sat Feb 02, 2013 7:38 pm
Score: 0 Give a positive score

Re: MouseButtonDown on Canvas

Postby luckyshot29 » Sun Feb 17, 2013 1:57 pm

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?
luckyshot29
 
Posts: 6
Joined: Sat Feb 02, 2013 7:38 pm
Score: 0 Give a positive score

Re: MouseButtonDown on Canvas

Postby skydereign » Sun Feb 17, 2013 7:05 pm

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?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: MouseButtonDown on Canvas

Postby moonforge » Mon Feb 18, 2013 2:18 am

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.
http://wannowandrichardsgames.weebly.com/

"You don't have to win to be a winner. You just have to pretend to be better than everyone else."

+ 1 please?
User avatar
moonforge
 
Posts: 45
Joined: Mon Jan 28, 2013 3:58 am
Location: CENSORED
Score: 8 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron