A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: no more rotating -- try horizontally flipping!

  1. #1
    damn, im smooth drkknght's Avatar
    Join Date
    Feb 2001
    Posts
    159

    no more rotating -- try horizontally flipping!

    i'm currently messing around with some game code, in an effort to personalize it. its a basic car-around-the-track type set up for now.

    the code they have is:

    Code:
    function setCarMove(d) {
    	if (d == 0) { nextX = pacX; nextY = pacY - 1; car._rotation = 90; }
    	else if (d == 1) { nextX = pacX + 1; nextY = pacY; car._rotation = 180; }
    	else if (d == 2) { nextX = pacX; nextY = pacY + 1; car._rotation = -90; }
    	else if (d == 3) { nextX = pacX - 1; nextY = pacY; car._rotation = 0; }
    so, turning left is done by "car._rotation = 180;"

    ...however... because of the graphics i've used, my car can't be roatated, or else it looks upside-down. is there a way to set this one variable to flip the image horizontally, instead?
    i'm not new to action scripting. i'm just bad at it.

  2. #2
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180

    :)

    You can use _xscale,
    _xscale = -100;

  3. #3
    damn, im smooth drkknght's Avatar
    Join Date
    Feb 2001
    Posts
    159
    heya saphua!

    hmm... that seems to have done what i asked for, but not what i wanted!

    altering that one variable meant that the rest of the script no longer operated as it should, because the rotations all depended upon one another (so fixing one direction just screws up another).

    oy!

    now, i'm not even sure how exactly i ask for help!

    i think what i'd need to do is somehow create a different movieclip for each direction...(??)
    i'm not new to action scripting. i'm just bad at it.

  4. #4
    Senior Member Dusarn's Avatar
    Join Date
    Mar 2003
    Location
    TX
    Posts
    157
    Try this I think that should fix the problem.
    code:

    function setCarMove(d)
    {
    if (d == 0)
    { nextX = pacX;
    nextY = pacY - 1;
    car._rotation = 90;
    car._xscale = 100;
    }else if (d == 1)
    { nextX = pacX + 1;
    nextY = pacY;
    car._rotation = 0;
    car._xscale = -100
    }else if (d == 2)
    { nextX = pacX;
    nextY = pacY + 1;
    car._rotation = -90;
    car._xscale = 100;
    }else if (d == 3)
    { nextX = pacX - 1;
    nextY = pacY;
    car._rotation = 0;
    }
    }


    Basically since we are changing the xscale if d==1, then we need to set the xscale back to how it originally was beforehand. Otherwise everything is going to be looking the opposite of what it should be. Also you need to set the cars rotation back to 0 before you do the -xscale to make it look right too.
    (Sorry I reformatted the code, I'm just used to doing it that way and I think its easier to read )
    Last edited by Dusarn; 03-05-2004 at 06:20 PM.

  5. #5
    damn, im smooth drkknght's Avatar
    Join Date
    Feb 2001
    Posts
    159
    heya dusarn!

    that almost works perfectly. everything flows as it should except when the car is headed to the right, and you want it to immediately go to the left. in that case, the car moves to the left, but is facing to the right.

    every other direciton works fine.

    man, this stuff is makin me nutty!
    i'm not new to action scripting. i'm just bad at it.

  6. #6
    Senior Member Dusarn's Avatar
    Join Date
    Mar 2003
    Location
    TX
    Posts
    157
    Sorry about that I was thinking the car had to make a full rotation to go in the opposite direction. So if the car can change directions from right to left then you just need to change back the xscale. For example: if the car is going right the xscale is at -100%(horizontally flipped), so then if you change the direction of the car to left then the car is still flipped(-100%) but is going in the opposite direction.

    So all you need to do too fix it is to add 'car._xscale = 100' in the (d == 3) section of the code.

  7. #7
    damn, im smooth drkknght's Avatar
    Join Date
    Feb 2001
    Posts
    159
    ahhh, gotcha!

    Code:
    function setCarMove(d)
    {
            if (d == 0)
            { nextX = pacX;
                    nextY = pacY - 1;
                    car._rotation = 90;
                    car._xscale = 100;
            }else if (d == 1)
            { nextX = pacX + 1;
                    nextY = pacY;
                    car._rotation = 0;
                    car._xscale = -100
            }else if (d == 2)
            { nextX = pacX;
                    nextY = pacY + 1;
                    car._rotation = -90;
                    car._xscale = 100;
            }else if (d == 3)
            { nextX = pacX - 1;
                    nextY = pacY;
                    car._rotation = 0;
                    car._xscale = 100;
            }
    }
    this works perfectly!!

    insanity = over! thank you so much!
    i'm not new to action scripting. i'm just bad at it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center