Drag and Drop

typtyp Member Posts: 6
edited November -1 in Working with GS (Mac)
Hi people,

can someone give me an insight on drag and drop? i tried the tutorial, but it didn´t worked out. I want to drag several actors to a target. i think this is possible, isn´t it?

best,

robin

Comments

  • typtyp Member Posts: 6
    Hi,

    thank you very much. But there is nothing in the file i downloaded. I checked it online, and its excactly what i need, but i cannot see it in my client. could you please check it?

    thanks!

    Robin
  • typtyp Member Posts: 6
    Oh, great. Thanks a lot!

    Robin
  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    How can I make a drag and drop behavior that drop in exact places (like a small grid)?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    is it possible to drag and slide something (like that shuffle board type game people play at bars?). In other words. you drag something for a little while and when you let go the object keeps moving in the direction you had been dragging it. Is this possible?
  • SlowboySlowboy Member, PRO Posts: 329
    I reckon you could do some trig maths by taking the start and the end x,y of the drag, then working out the angle of the line between them. I wouldn't have a clue though, as I'm no good at trig.
    Then, depending on which of these was easier, or indeed, possible in Game Salad, either make the actor move along that angle or extend the line (with more maths) and generate a destination x,y for the character to move towards.
    I'm sure that both options are possible in GS, given the right maths.
    Any programmers around......?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    if I drag an object does it have momentum? So when I let go it keeps sliding. Or do I need to use math to give the illusion of momentum?
  • billpaternobillpaterno Member Posts: 26
    I would love to know how to code a drag and slide!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    have an attribute in the actor called "dragging".
    When you click actor, and mouse is inside, set dragging to true
    When you release mouse, set dragging to false

    have a rule in the actor that says:
    When dragging is true, constrain my x and y to the mouseX and mouseY

    When you initially touch the actor, capture that X and Y into 2 attributes: initX and initY.

    When you release the mouse, capture that position into two attributes called currentX and currentY

    So, first we need to find the "force" of the flick, i.e. the distance you dragged the actor.
    to find that, subtract the attributes like this, using the pythagorean theorem:

    a2 = b2 + c2
    (the 2's are the power... a squared = b squared + c squared)

    You are trying to find a, which is the length of the line segment between the initial coordinates and the current ones.

    create a new attribute in the actor called "flickforce"

    so it will look like this:

    flickforce = sqrt((abs(currentX - initX) + abs(currentX - initX)) + (abs(currentY - initY) + abs(currentY - initY)))

    abs() is a math function (short for "absolute") , which always will return a positive number, so if the answer is either -6 or 6 - abs will return 6.
    because the force is always going to be positive, we make sure it is by using abs.

    So that's the length of the line, the longer the line, the greater the force. you should probably set a maxForce attribute as well.

    next you'll need the angle in which to send the actor:

    luckily, gamesalad has a nice math function called vectorToAngle

    flickAngle = vectorToAngle(currentX - initX,currentY - initY)
    (the angle CAN be negative, so we don't use abs here)

    Then, plug flickforce and flickAngle into an accelerate behavior.

    Youll probably have to multiply the flickforce by a number to get it high enough that it looks ok,
    but this is the general idea.

    hope this helps!
    Joe
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    ugh. Sorry I have to ring in on this.

    flickforce = sqrt((abs(currentX - initX) + abs(currentX - initX)) + (abs(currentY - initY) + abs(currentY - initY)))

    should be:
    flickforce = sqrt((abs(currentX - initX) * abs(currentX - initX)) + (abs(currentY - initY) * abs(currentY - initY)))

    or in short:
    flickforce = magnitude(currentX - initX , currentY - initY)

    Math man...AWAY!!!! <flies off>
  • firemaplegamesfiremaplegames Member Posts: 3,211
    oops!

    yes! sorry, i was just typing too fast!
    i must mind my asterisks!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Would it possible for one of you guys to make a downloadable game project with an actor that is "flickable"?

    pretty please?!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Magnitude!!

    I didn't even realize that was there!

    That will certainly save me some time - entering in the pythagorean formula into the expressions editor was a tad brutal!

    I'll see if i can whip up a demo.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Thanks firemaple! can't wait to try it out!
  • stanimationstanimation Member Posts: 406
    Yeah I'm with scitunes! pretty please!! Cause this kind of stuff makes my head hurt!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Anybody have any luck with this?

    ... sugar on top ...

    ;-P
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    I have something going, but it's not perfect yet. i need some answers with the physics stuff...

    I'll post a little later.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Thanks, Man!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Does anybody know if there is a spot in the wiki that explains all the math stuff that comes up in the expression editor under the second pull down menu (the one that has a bunch of gobely-gook including "random" which is the only one that I have any clue about)?

    If I knew more about those features I would try this drag and slide function on my own, but I just feel helpless because even IF I knew the math for this I wouldn't know how to get it into GS.

    Thanks!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    (i answered this in the other thread but it got buried...)

    I can help you with some of the easier ones...

    RANDOM
    Very handy, gives you a random number between two numbers that you specify, i.e "Please give me a random number between 2 and 13."

    FLOOR
    This rounds a number DOWN to the nearest integer. i.e, floor(4.5) will round it down to 4, or floor(1.984375347389475) will round it down to 1

    CEIL
    The opposite of floor. Will round a number UP to the nearest integer. i.e, 4.3 becomes 5, and 1.000001 becomes 2

    GameSalad doesn't seem to have just a ROUND math function, which would round a number up or down, i.e 4.3 becomes 4 and 4.9 becomes 5. I'm not sure why it isn't included, although computers do have rounding errors, which can cause havoc.

    ABS
    Short for Absolute. This always returns a positive number. i'm not a math major, but it sort of works like this:
    abs(-5) will give you the answer: 5. as will abs(5)... they both give you the "distance" that number is from 0.
    In this case, both 5 and -5 are 5 units away from 0. does that make sense?
    abs is very handy for always returning a positive number, especially when subtracting 2 numbers. it is used all the time in this situation:

    I need to find out how far I travelled on the x axis from my starting location. So the math formula for that is: (currentX - initialX) This will give me the distance I travelled. However, I could have travelled to the LEFT or RIGHT from my starting X. and if i subtract them like that, going to the left will give me a negative number. i want the distance to always be positive. so i use abs like this: abs(currentX - initX)

    MAX
    This returns the greater of two values. it is used like this max(6,3) will return 6. Or in this case:max(player1Score, Player2Score) whichever is higher. very useful for comparing two numbers.

    MIN
    The opposite of max. returns the lower number.

    Those are the easier ones, the other ones require geometry and trigonometry.
    But those are very useful as well, especially in games where you use angles, trajectories, etc.

    Someone smarter than me should explain them though!

    Hope this helps!
    Joe
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @scitunes: I just added my attempt to try and do this here:

    http://gamesalad.com/game/play/30692

    let me know what you think!

    Best,
    Joe
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Thanks! I really appreciate it. I'll let you know how it goes.
  • snitzpawsnitzpaw Member Posts: 1
    @firemaplegames: thanks for putting this together! excited to check out how you did that!
Sign In or Register to comment.