# Making a shooting game, would like the gun to flip \_xscale

**URL:** <https://forum.kirupa.com/t/making-a-shooting-game-would-like-the-gun-to-flip--xscale/262032>\
**Category:** Uncategorized\
**Created:** [June 2, 2008, 8:02pm UTC](https://forum.kirupa.com/t/making-a-shooting-game-would-like-the-gun-to-flip--xscale/262032 "2008-06-02T20:02:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Line](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@Line](https://forum.kirupa.com/u/Line)\
**Post date:** [June 2, 2008, 8:02pm UTC](https://forum.kirupa.com/t/making-a-shooting-game-would-like-the-gun-to-flip--xscale/262032/1 "2008-06-02T20:02:51Z")

</div>

I’m making a shooting game, would like the gun to flip \_xscale when you move the gun past half the width of the stage.

Here’s the script I made which doesn’t work and is probably not written correctly:

if(\_xmouse \>= Stage.width/2){  
\_root.gun\_mc.\_xscale \* -1;  
}

Thanks ahead for your reply/answers

-Line

---

<div class="post-metadata">

**Author:** ![Line](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@Line](https://forum.kirupa.com/u/Line)\
**Post date:** [June 2, 2008, 8:10pm UTC](https://forum.kirupa.com/t/making-a-shooting-game-would-like-the-gun-to-flip--xscale/262032/2 "2008-06-02T20:10:26Z")

</div>

I guess I should also add that, the gun\_mc is following the mouse on the x axis in case anyone is confused.

-Line

[quote=Line;2335042]I’m making a shooting game, would like the gun to flip \_xscale when you move the gun past half the width of the stage.

Here’s the script I made which doesn’t work and is probably not written correctly:

if(\_xmouse \>= Stage.width/2){  
\_root.gun\_mc.\_xscale \* -1;  
}

Thanks ahead for your reply/answers

-Line[/quote]

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 2, 2008, 8:20pm UTC](https://forum.kirupa.com/t/making-a-shooting-game-would-like-the-gun-to-flip--xscale/262032/3 "2008-06-02T20:20:19Z")

</div>

```auto
if (_xmouse >= Stage.width / 2) {
 _root.gun_mc._xscale *= -1;
}

```

---

<div class="post-metadata">

**Author:** ![Line](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@Line](https://forum.kirupa.com/u/Line)\
**Post date:** [June 2, 2008, 8:49pm UTC](https://forum.kirupa.com/t/making-a-shooting-game-would-like-the-gun-to-flip--xscale/262032/4 "2008-06-02T20:49:47Z")

</div>

Thanks Glos, you were close, the \*= is the correct usage to multiply. What I didn’t know was that the number is the percentage and not an actual number to multiply by. So the number is -100.

Only downside to the script that we have now is that it only occured once. I needed a listener or something to keep checking to see if the x coordinate of the mouse had changed.

The script that seems to be working correctly is:

\_root.onMouseMove = function(){  
if(\_xmouse \>= Stage.width/2){  
trace(“it is at more than half!”);  
\_root.gun\_mc.\_xscale = 100;  
}else{  
trace(“it is at less than half!”);  
\_root.gun\_mc.\_xscale = -100;  
}  
}

Thanks for replying!  
-Line

[quote=glosrfc;2335053] ActionScript Code:  
[LEFT][COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]\_xmouse[/COLOR] \>= [COLOR=#0000FF]Stage[/COLOR].[COLOR=#0000FF]width[/COLOR] / [COLOR=#000080]2[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]gun\_mc[/COLOR].[COLOR=#0000FF]\_xscale[/COLOR] \*= -[COLOR=#000080]1[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[/LEFT]

[/quote]

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 2, 2008, 9:09pm UTC](https://forum.kirupa.com/t/making-a-shooting-game-would-like-the-gun-to-flip--xscale/262032/5 "2008-06-02T21:09:23Z")

</div>

So the number is -100?

Let’s say that your movie is 50 pixels wide:  
\_xscale= 100; // mc is still 50 pixels wide  
\_xscale\*= -1 // 100 \* -1 = -100 so mc is flipped but still 50 pixels wide  
As you can see, = -100 and \*= -1 are both the same

But what if you’ve already resized your movie, say by 50%?  
\_xscale= 50; // mc is resized to 25 pixels wide

Now, if you use \_xscale= -100, your movie is flipped but it reverts back to the original 50 pixel width. However, if you use \_xscale\*= -1, then 50 \* -1 = -50 so your movie is flipped but it still retains your amended scaling of 25 pixels.

So -100 isn’t the number in these circumstances. Hope that explanation helps.

And updateAfterEvent() might help solve the other problem…check it out in the Help files.
