View Full Version : [AS2] Moving Counter in a Dice Game
Llama_Boy
12-21-2008, 06:14 PM
Hi Everyone
Im creating a simple board game where the pieces will move round a circular board.
I've created the dice and can track the value of the roll. The problem is actually moving the counter by the amount of the dice roll.
I'm trying to move the counter to match the _x and _y of the resulting square, so that the counter will sit in the middle of the square, but cant figure out how to do it. Any help would be appreciated
:)
Bod720
12-21-2008, 06:22 PM
Upload your .fla :)
Llama_Boy
12-21-2008, 06:38 PM
on (press) {
dice1.roll();
dice2.roll();
diceCount = dice1.rollValue+dice2.rollValue;
diceTrack.text = diceCount;
p1Move = diceCount+p1Move;
if (p1Move>24) {
p1Move = p1Move-24;
}
}
This is the actionscript for the roll button, there is no other script at the moment that has any affect on the game. DiceTrack is a textbox for debugging just to make sure the dice roll is being captured.
The board is 24 squares round, which is why p1Move has the -24 when it passes the start again.
The squares are all given the instance name space1, space2, space3.....................space24, so i thought to do something along the lines of:
var p1Track:String = "Space" + p1Move;
Counter1._x = p1Track._x;
Counter1._y = p1Track_y;
Let me know if you need any more info
Llama_Boy
12-21-2008, 06:53 PM
Here's the .fla
http://www.mediafire.com/file/vyjwjmq2b3d/Project.fla
Llama_Boy
12-21-2008, 08:11 PM
Hi Everyone
I'm trying to create a simple board game where the player will navigate around a board of 24 squares.
I have created the dice, which record the diceroll and store it in a number variable. The problem is mapping the counter to the variable so as to move to the correct square.
Does anyone know a way of making a counters movement based on a variable? Any help would be appreciated.
:)
Bod720
12-21-2008, 08:53 PM
Hi. You can find the file here:
www.Bod720.co.nr/Project2.fla
Also, I'm not sure how exact it will be, since I've used rotation to move the counter, so what you may need to do it put somewhere on the main timeline something like:
onEnterFrame = function () {
if(Counter1._rotation <=-2 || Counter1._rotation >=2) {
Counter1._rotation = 0
}
}
This just means it'll reset the rotation when it is 2 degrees either side of 0.
Any other questions? Feel free to ask!
Llama_Boy
12-21-2008, 10:26 PM
Thanks for the help Bod
Unfortunately i cant seem to open the .fla. Just says failed to open file.
I tried using the code sample you gave but im guessing there is more you added than that so i cant integrate it.
:(
Bod720
12-22-2008, 09:01 AM
It won't open because of the version of Flash you are using. What version do you need me to save it to?
You can calculate an X and Y position on a circle by using Math.sin(angle) and Math.cos(angle) where angle is in radians. ( 0.. 2PI )
You could also manually position a series of invisible movieclips, named square1, square2, square3, etc. and access their position with this['square'+squareInt]._x
Llama_Boy
01-05-2009, 01:15 PM
It won't open because of the version of Flash you are using. What version do you need me to save it to?
I'm using MX 2004. Thanks again for the help
Llama_Boy
01-05-2009, 01:52 PM
rrh, i attempted to make the counter move using the method you describe by storing the name of the movie clips in a variable. This doesnt seem to work dynamically though, it can only work if i tell it the exact space i want it to align to.
Is it possible to tell flash to read the value of a variable, check for the movie clip with the same name and then align to that?
I don't understand. Give an example of what works and what doesn't work for you.
Bod720
01-05-2009, 07:42 PM
I'm using MX 2004. Thanks again for the help
Ok, I'll save it to that soon. Also, do you want it so that you can see it moving round the board?
Llama_Boy
01-05-2009, 09:20 PM
That would be great, thanks. Please don't go out of your way though.
Llama_Boy
01-05-2009, 09:31 PM
I don't understand. Give an example of what works and what doesn't work for you.
I have a set of movie clips named space1, space2, space3 etc. I have a diceCount variable that tracks where the space number where the counter should be.
I tried to append the word 'Space' to the variable (which then returns the name of the movie clip where the counter should appear) and then tell the counter to match the _x and _y of that result to move it there.
I can get this to work if i tell Flash to move the counter specifically to 'Space2' for example, but not using the variable to move the counter to where the diceroll says it should go.
I hope that all makes sense. Finding it quite difficult to explain
I hope that all makes sense. Finding it quite difficult to explainWould it be easier for you to give an example of what works and what doesn't work?
Like you go:
This works:
...
This doesn't work:
....
Because there's a million things you could be doing wrong, but if I can see the difference between what is and isn't working, I might see something.
Llama_Boy
01-06-2009, 12:26 PM
This Works:
Counter1._x = _root.Space10._x
Counter1._y = _root.Space10._y
This doesn't work:
var test:String = "Space";
var test2:String = test.concat(p1Move);
Counter1._x = _root.test2._x;
Counter1._y = _root.test2._y;
p1Move stores the number of the square where the counter should appear. Test2 shows 'Space1', 'Space2' or whatever it may happen to be.
I see now:
Counter1._x = _root[test2]._x;
Llama_Boy
01-06-2009, 03:13 PM
That's got it.
Thanks a million rrh, and Bod720. I've been wrestling with that for days!
:)
My original example used:this['square'+squareInt]._x
It uses 'this' instead of '_root' and '+' instead of 'concat' but the basic concept is still there.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.