Working with click (touch) to move
![BRGKeen](http://forums.gamesalad.com/applications/dashboard/design/images/defaulticon.png)
Hey all, this is my first post here. I have spent the better part of a week reading these forums 3 hours a day -- great info!
I'm working on creating an adventure game similar to the old Lucas Arts and Sierra games like King's Quest V and I need to get my point and click (or touch to move as it is on the iphone) working properly.
I have an invisible actor with:
when touch is pressed, game.move is 1
On my movable actor:
When game.move is true, 'move to' touch 1x and touch 1y.
The problem I'm having is that after the first click (when the movable actor reaches the spot) he stops and I can not click again to move him.
How can I make it so that when I click (or touch) the actor will move to that spot (not instantly snap there, but take time to "walk there" since it's a character)? I'd like it if I can click it and have him go there regardless of whether or not he reached his first destination -- I'd like the most recent touch to overwrite.
That's my first question.
Second question:
What can I do to have the actor "turn" to face the click? (Up, down, left, right) The game is set up on a fixed angle and if I click above the actor I want his back to face me and it animate him walking in that direction.
I look forward to any responses you guys can offer and to a wonderful relationship with the Gamesalad community.
I'm working on creating an adventure game similar to the old Lucas Arts and Sierra games like King's Quest V and I need to get my point and click (or touch to move as it is on the iphone) working properly.
I have an invisible actor with:
when touch is pressed, game.move is 1
On my movable actor:
When game.move is true, 'move to' touch 1x and touch 1y.
The problem I'm having is that after the first click (when the movable actor reaches the spot) he stops and I can not click again to move him.
How can I make it so that when I click (or touch) the actor will move to that spot (not instantly snap there, but take time to "walk there" since it's a character)? I'd like it if I can click it and have him go there regardless of whether or not he reached his first destination -- I'd like the most recent touch to overwrite.
That's my first question.
Second question:
What can I do to have the actor "turn" to face the click? (Up, down, left, right) The game is set up on a fixed angle and if I click above the actor I want his back to face me and it animate him walking in that direction.
I look forward to any responses you guys can offer and to a wonderful relationship with the Gamesalad community.
Comments
Well, let's assume you do have a HUD so what I would do is make your invisible actor cover the touchable part of the scene.
Then I would have a rule that says
When touch is pressed
change game.move to 1
OTHERWISE
change game.move to 0 (you can use 0 for false and 1 for true in GS with booleans)
Then in the character:
when game.move is true
move to touch1.x , touch1.y
--------------------Rotation-------------------
Create an angle attribute (game.HeroAngle)
Create a self interger attribute (self.ImageNumber)
In the character
when game.move is true
constrain game.HeroAngle to vectorToAngle(self.positionX-touch1.X, selfpositionY-touch1.y)
constrain self.ImageNumber (floor(game.HeroAngle/90) (if you have four images, divde by 45 if you have 8)
Then name your images like this - "image1.png"
then do this constrain self.image to "image"..self,ImageNumber..".png"
The movement is now working perfectly. I'll try the rotation next and let you know hot it goes. I'll likely have more questions.
Thank you.
**Edit**
I've reached the last line in your explanation and I'm having trouble understanding what it means.
You said:
then do this constrain self.image to "image"..self,ImageNumber..".png"
Does that mean after the constrain self.ImageNumber to floor(game.HeroAngle/90) I add another constrain?
I've added constrain self.Image but I don't know what to put in the "To:" after that.
Also, how would I get it to not just change to an image but to an animation. Perhaps that will alter how this is done.
I would like my actor or "character" to animate in the direction it is moving.
Another Edit here.
The more I think about it, the more I realize maybe I don't need a rotate but simply an image change and an animation.
I've been trying stuff like:
self.Position.X < game.Touches.Touch 1.X
then Change Image
Animate
That doesn't work. The character's image does not change well since if I choose an angle it's freaking out because it doesn't know if it should consider the X or the Y.
I want to make my character move like how a character would move in a game like Diablo. The screen should scroll/truck along with the character. Before I used the "Move To" attribute but the actor would just follow the mouse around. Right now I am using two constrain attributes so the character moves to the mouse position instantly when clicked.
However, I am not sure how to make that actor move slowly to where I clicked.
I guess my real question is - how do I make the actor move like it was a character in a top down isometric game(i.e diablo, starcraft, torchlight.)
".." is a powerful little trick. It lets you place attributes into the middle of file names.
So all you need to do is use the code I posted above. Name your pngs so they are identical except for one number:
image1.png
image2.png
image3.png
image4.png
So constrain self.image to "image"..self.ImageNumber..".png" will insert 1,2,3, or 4 into the image file name depending on the direction the character is walking. The key is to type it exactly as I posted but DO NOT type in the attribute (self.ImageNumber) you must select that from the drop down list or it will not work.
I have 4 images.
image1.png is my facing forward (Down)
image2.png is facing right.
image3.png is facing left.
image4.png is facing away (up)
Click right of my actor, the proper picture appears and he moves right. Clicking Left, a white box appears. Clicking up a white box appears. Click down the proper picture appears. Sometimes clicking randomly too close to my actor gets me the wrong image for any direction.
So only right and down are working, but left and up are not. Sometimes when the character is higher up on the Y axis and I click for it to go down, the Up image appears.
I assume it has something to do with:
constrain self.ImageNumber to floor(game.HeroAngle/90)
Can you think of any reason why it's messing up?
Also, once I have all 4 directions working, how would I go about animating them so that I can add 2-3 frames to each direction?
**EDIT**
Major breakthrough. This tutorial I found this post: http://gamesalad.com/wiki/how_tos:gsc_animate_direction which does exactly what I want. It animates in the direction I want them to go and I can fake the turn with animations. I just added Y linear motion.
HOWEVER
When He moves at angles I am in trouble because it freaks out swapping between the X and Y image. That's all I need to figure out how. Any suggestions?
http://gamesalad.com/wiki/how_tos:gsc_animate_direction
I have it working if I go perfectly up, perfectly left, perfectly down (X and Y) but if I go at any angle, as in any X or Y combined it freaks out flipping between the animation for X and Y. It pretty much has to be exactly left, right, up, down for it to work properly.
I've done exhaustive searches and can't get anything to work properly.
Search in the GS creator start screen for "Automatic Image Change"
Also, how do I create it now so that he animates in the direction of movement?