<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Making objects snap to a grid</title>
	<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/</link>
	<description></description>
	<pubDate>Fri, 10 Feb 2012 19:20:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Squornshellous Beta</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-207000</link>
		<dc:creator>Squornshellous Beta</dc:creator>
		<pubDate>Fri, 16 Sep 2011 10:24:31 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-207000</guid>
		<description>If you want the code to work with multiple objects, you simply have to define names for the functions. So the first object might have this code:
&lt;blockquote&gt;onClipEvent(enterFrame) {
this.onPress=function(object1press) {
Mouse.hide();
this._alpha=40;
this._x=_root._xmouse;
this._y=_root._ymouse;
startDrag(this);
}
this.onRelease=function(object1release) {
Mouse.show();
this._alpha=100;
this._x=(Math.round(_root._xmouse/25))*25;
this._y=(Math.round(_root._ymouse/25))*25;
stopDrag();
}
}&lt;/blockquote&gt;

And then the second might say:
&lt;blockquote&gt;onClipEvent(enterFrame) {
this.onPress=function(object2press) {
Mouse.hide();
this._alpha=40;
this._x=_root._xmouse;
this._y=_root._ymouse;
startDrag(this);
}
this.onRelease=function(object2release) {
Mouse.show();
this._alpha=100;
this._x=(Math.round(_root._xmouse/25))*25;
this._y=(Math.round(_root._ymouse/25))*25;
stopDrag();
}
}&lt;/blockquote&gt;

And so on, for each new object.</description>
		<content:encoded><![CDATA[<p>If you want the code to work with multiple objects, you simply have to define names for the functions. So the first object might have this code:</p>
<blockquote><p>onClipEvent(enterFrame) {<br />
this.onPress=function(object1press) {<br />
Mouse.hide();<br />
this._alpha=40;<br />
this._x=_root._xmouse;<br />
this._y=_root._ymouse;<br />
startDrag(this);<br />
}<br />
this.onRelease=function(object1release) {<br />
Mouse.show();<br />
this._alpha=100;<br />
this._x=(Math.round(_root._xmouse/25))*25;<br />
this._y=(Math.round(_root._ymouse/25))*25;<br />
stopDrag();<br />
}<br />
}</p></blockquote>
<p>And then the second might say:</p>
<blockquote><p>onClipEvent(enterFrame) {<br />
this.onPress=function(object2press) {<br />
Mouse.hide();<br />
this._alpha=40;<br />
this._x=_root._xmouse;<br />
this._y=_root._ymouse;<br />
startDrag(this);<br />
}<br />
this.onRelease=function(object2release) {<br />
Mouse.show();<br />
this._alpha=100;<br />
this._x=(Math.round(_root._xmouse/25))*25;<br />
this._y=(Math.round(_root._ymouse/25))*25;<br />
stopDrag();<br />
}<br />
}</p></blockquote>
<p>And so on, for each new object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vladimir</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-173452</link>
		<dc:creator>Vladimir</dc:creator>
		<pubDate>Sat, 07 May 2011 18:57:51 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-173452</guid>
		<description>This is good code but if there is more object everyone with this script code doesn't working is there any sugestion?</description>
		<content:encoded><![CDATA[<p>This is good code but if there is more object everyone with this script code doesn&#8217;t working is there any sugestion?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shadow Hunter</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-42604</link>
		<dc:creator>Shadow Hunter</dc:creator>
		<pubDate>Tue, 26 Jan 2010 17:06:24 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-42604</guid>
		<description>Here is how to do it in AS3 which runs WAY faster then AS2,
everyone should learn to use AS3 and get rid of AS2 like we did with AS1.

This is with a separate document class NOT on the main timeline because it is a bad habit for AS3.

package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
	
public class Main extends
MovieClip
{
var box:Sprite = new Sprite ();
var Click:Boolean = new Boolean (false);
var gridSize:int = 10;
var i:int = gridSize;
		
public function Main ()
{
this.addEventListener (Event.ENTER_FRAME, EF);
box.graphics.lineStyle (1, 0x000000);		
box.graphics.beginFill (0x000000);	
box.graphics.drawRect (0, 0, gridSize, gridSize);	
box.graphics.endFill();	
this.addChild (box);	
box.addEventListener (MouseEvent.CLICK, MC);
}
		
private function MC (e:MouseEvent)
{
if (!Click)
{
box.startDrag(false);			
Click = true;
}	
else if (Click)
{				
box.stopDrag();			
Click = false;
}
}
		
private function EF (e:Event)
{
if (Click)
{				
while (1)
{					
if(mouseX&lt;i)					
{					
box.x = (i - gridSize);
i = gridSize;
break;
}
i  = gridSize;
}
while (1)
{
if (mouseY &lt; i)
{
box.y = (i - gridSize);
i = gridSize;
break;
}
i  = gridSize;
}
}
}
}
}</description>
		<content:encoded><![CDATA[<p>Here is how to do it in AS3 which runs WAY faster then AS2,<br />
everyone should learn to use AS3 and get rid of AS2 like we did with AS1.</p>
<p>This is with a separate document class NOT on the main timeline because it is a bad habit for AS3.</p>
<p>package<br />
{<br />
import flash.display.MovieClip;<br />
import flash.display.Sprite;<br />
import flash.events.Event;<br />
import flash.events.MouseEvent;<br />
import flash.ui.Mouse;</p>
<p>public class Main extends<br />
MovieClip<br />
{<br />
var box:Sprite = new Sprite ();<br />
var Click:Boolean = new Boolean (false);<br />
var gridSize:int = 10;<br />
var i:int = gridSize;</p>
<p>public function Main ()<br />
{<br />
this.addEventListener (Event.ENTER_FRAME, EF);<br />
box.graphics.lineStyle (1, 0&#215;000000);<br />
box.graphics.beginFill (0&#215;000000);<br />
box.graphics.drawRect (0, 0, gridSize, gridSize);<br />
box.graphics.endFill();<br />
this.addChild (box);<br />
box.addEventListener (MouseEvent.CLICK, MC);<br />
}</p>
<p>private function MC (e:MouseEvent)<br />
{<br />
if (!Click)<br />
{<br />
box.startDrag(false);<br />
Click = true;<br />
}<br />
else if (Click)<br />
{<br />
box.stopDrag();<br />
Click = false;<br />
}<br />
}</p>
<p>private function EF (e:Event)<br />
{<br />
if (Click)<br />
{<br />
while (1)<br />
{<br />
if(mouseX<i)<br />
{<br />
box.x = (i - gridSize);<br />
i = gridSize;<br />
break;<br />
}<br />
i  = gridSize;<br />
}<br />
while (1)<br />
{<br />
if (mouseY < i)<br />
{<br />
box.y = (i - gridSize);<br />
i = gridSize;<br />
break;<br />
}<br />
i  = gridSize;<br />
}<br />
}<br />
}<br />
}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mipper</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-25345</link>
		<dc:creator>mipper</dc:creator>
		<pubDate>Tue, 30 Dec 2008 21:33:34 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-25345</guid>
		<description>This is waaaaay too complicated.
This code works even better if you just put it into the script of your movie clip:

onClipEvent(enterFrame) {
   this.onPress=function() {
      Mouse.hide();
      this._alpha=40;
      this._x=_root._xmouse;
      this._y=_root._ymouse;
      startDrag(this);
   }
   this.onRelease=function() {
      Mouse.show();
      this._alpha=100;
      this._x=(Math.round(_root._xmouse/25))*25;
      this._y=(Math.round(_root._ymouse/25))*25;
      stopDrag();
   }
}

Just replace 25 with your grid size and this code will work perfect.
Its also AS 2.</description>
		<content:encoded><![CDATA[<p>This is waaaaay too complicated.<br />
This code works even better if you just put it into the script of your movie clip:</p>
<p>onClipEvent(enterFrame) {<br />
   this.onPress=function() {<br />
      Mouse.hide();<br />
      this._alpha=40;<br />
      this._x=_root._xmouse;<br />
      this._y=_root._ymouse;<br />
      startDrag(this);<br />
   }<br />
   this.onRelease=function() {<br />
      Mouse.show();<br />
      this._alpha=100;<br />
      this._x=(Math.round(_root._xmouse/25))*25;<br />
      this._y=(Math.round(_root._ymouse/25))*25;<br />
      stopDrag();<br />
   }<br />
}</p>
<p>Just replace 25 with your grid size and this code will work perfect.<br />
Its also AS 2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nilesh</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-6227</link>
		<dc:creator>nilesh</dc:creator>
		<pubDate>Tue, 24 Jul 2007 11:15:24 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-6227</guid>
		<description>This is amazing i mean how its possible ohh i dont know much scripting but wow!!!</description>
		<content:encoded><![CDATA[<p>This is amazing i mean how its possible ohh i dont know much scripting but wow!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: awesty</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5976</link>
		<dc:creator>awesty</dc:creator>
		<pubDate>Sat, 07 Jul 2007 03:23:46 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5976</guid>
		<description>Okay, although I'm probably not the best person to ask about optimized code.

If you really want your game to be fast learn AS3, it is roughly 10 times faster than AS2 and it is setup so you practically have to optimize.</description>
		<content:encoded><![CDATA[<p>Okay, although I&#8217;m probably not the best person to ask about optimized code.</p>
<p>If you really want your game to be fast learn AS3, it is roughly 10 times faster than AS2 and it is setup so you practically have to optimize.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: awesty</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5975</link>
		<dc:creator>awesty</dc:creator>
		<pubDate>Sat, 07 Jul 2007 03:22:10 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5975</guid>
		<description>No, it is different here.

We have 4 terms in a school year (which each go for about 9-11 weeks) and they are all separated by 2 week holidays.

Then after the 4th term we have Christmas holidays which go for 6 weeks.

So we have 3 lots of 2 weeks breaks a 6 week break at the end, instead of one big break over Summer. It still works out the same though.</description>
		<content:encoded><![CDATA[<p>No, it is different here.</p>
<p>We have 4 terms in a school year (which each go for about 9-11 weeks) and they are all separated by 2 week holidays.</p>
<p>Then after the 4th term we have Christmas holidays which go for 6 weeks.</p>
<p>So we have 3 lots of 2 weeks breaks a 6 week break at the end, instead of one big break over Summer. It still works out the same though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bitwize</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5943</link>
		<dc:creator>Bitwize</dc:creator>
		<pubDate>Wed, 04 Jul 2007 08:30:27 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5943</guid>
		<description>happy holidays Awesty!

wondering if you could do a tute on "general optimisation" (and not just for tile games :P) 

eg: what are some ways to speed up your game etc... when to use Mr.vector and Mrs.Bitmap,effecient loops etc...

Ta :)~</description>
		<content:encoded><![CDATA[<p>happy holidays Awesty!</p>
<p>wondering if you could do a tute on &#8220;general optimisation&#8221; (and not just for tile games :P) </p>
<p>eg: what are some ways to speed up your game etc&#8230; when to use Mr.vector and Mrs.Bitmap,effecient loops etc&#8230;</p>
<p>Ta :)~</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gankro</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5931</link>
		<dc:creator>Gankro</dc:creator>
		<pubDate>Tue, 03 Jul 2007 17:09:24 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5931</guid>
		<description>Jesus school goes late in Australia! Wait two weeks holiday? You taking summer school too?</description>
		<content:encoded><![CDATA[<p>Jesus school goes late in Australia! Wait two weeks holiday? You taking summer school too?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: awesty</title>
		<link>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5874</link>
		<dc:creator>awesty</dc:creator>
		<pubDate>Tue, 03 Jul 2007 04:01:44 +0000</pubDate>
		<guid>http://www.awestyproductions.com/tutorials/flash-tutorials/making-objects-snap-to-a-grid/#comment-5874</guid>
		<description>Yea. I had started learning C++ and started trying to make a vehicle physics engine in flash, and I was starting to play guitar heaps AND it was the last week of school so I had heaps of work to finish.

But, 2 weeks holiday now so I should be able to post every few days.</description>
		<content:encoded><![CDATA[<p>Yea. I had started learning C++ and started trying to make a vehicle physics engine in flash, and I was starting to play guitar heaps AND it was the last week of school so I had heaps of work to finish.</p>
<p>But, 2 weeks holiday now so I should be able to post every few days.</p>
]]></content:encoded>
	</item>
</channel>
</rss>








<!-- analytics977 --> 
