Drag and Drop
typ
Member Posts: 6
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
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
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
Robin
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......?
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
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>
yes! sorry, i was just typing too fast!
i must mind my asterisks!
pretty please?!
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.
... sugar on top ...
;-P
I have something going, but it's not perfect yet. i need some answers with the physics stuff...
I'll post a little later.
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!
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
http://gamesalad.com/game/play/30692
let me know what you think!
Best,
Joe