Getting the top left corner of a grid cell (math problem)

I'm making a map editor for a tile based game. The editor makes a grid:
private function drawGrid():void {
            var grid:Sprite = new Sprite();
            var tileSize:uint= 50;
            for(var i:int=0;i<row;i++)
                grid.graphics.lineStyle(1,0x000000,0.3);
                grid.graphics.moveTo(0, i*tileSize);
                grid.graphics.lineTo(700, i*tileSize);
            for(var j:int=0;j<column;j++)
                grid.graphics.lineStyle(1,0x000000,0.3);
                grid.graphics.moveTo(j*tileSize, 0);
                grid.graphics.lineTo(j*tileSize, 400);
            stage.addChild(grid);
And when the user clicks anywhere in the screen a movieclip is added to stage. The movieclip (exported for actionscript as Tile) should be placed in the top left corner of the grid cell.
private function placeTile(mouseX:int, mouseY:int, frame:uint):void {
            var tile:Tile = new Tile();
            tile.gotoAndStop(frame);
            tile.x = PROBLEM HERE
            tile.y = PROBLEM HERE
            stage.addChild(tile);
How can I do that? I came up with an idea but it didn't work because I have a math problem.  Let's pretend that the user mouse is at position mouseX = 456:
I could remove the hundreds and use the quotient 56 and check if it is above 50. If it is above 50 I would place it at x = 500 if not I would place it at x = 450. How can I remove the hundreds? Do you have a better idea?
Message was edited by: wilsonsilva7 because unconsciously I pressed ctrl+s (to save) and the message was posted

Thanks. I asked a friend and he told me about the %but I still had a problem. Your expression solved my problem
        private function placeTile(mouseX:int, mouseY:int, frame:uint):void {
            var tile:Tile = new Tile();
            tile.gotoAndStop(frame);
            tile.x = Math.floor(mouseX / tileSize) * tileSize;
            tile.y = Math.floor(mouseY / tileSize) * tileSize;
            stage.addChild(tile);
That way every tile is centered every 50 pixels

Similar Messages

  • HT4993 my iphone4 says searching in the top left corner how do i get it to stop and get my service back?

    my iphone4 says searching in the top left corner and i can not make calls or get calls how do i fix it so i have my service back

    you can try a reset, hold down the home/sleep button until you see the apple logo and then release, then wait fro the phone to boot back up.
    if that doesn't work contact your cell provider

  • How do I get my Sony ebook Reader to show up ("be recognized") in the top left corner??

    How do I get my Sony ebook reader to show up ("be recognized") in the top left corner of the window.  It never shows up and I cannot transfer books from my Mac computer to ADE.  I am using Sony Reader Library but it is developing problems!!  Can anyone assist??

    No solution yet.  One would think that Adobe would recognize that several complaints  have been reported on this problem.  Obviously, nobody knows how to fix it!!  Sorry I can't be helpful!!

  • Under Windows 7, 64-bit, Firefox intermittently will not open a new window - all I get is a grey screen, with a tiny part of my homepage displayed in the top left corner of the screen.

    The problem began after a recent Firefox update. Occasionally, when I try to open a new Firefox window, all I get is a grey screen with a tiny section of my homepage visible in the top left corner of the screen. NOTE: Firefox stores all of these aborted attempts, as, whenever I close it and then re-open it, the first time I open a new window it automatically opens all of the windows that had originally failed to open.
    == This happened ==
    Every time Firefox opened
    == on or about June 26, 2010

    Got the exact same problem aswell, finally fed up with it now as i just started up firefox and 14 new windows opened because of this bug, luckily my computer can handle them but someone with a slower processor it would have been a nightmare, needs fixing ASAP.
    Reverting back to 3.6.3 until this issue is solved. (link for anyone wanting to do the same below)
    http://www.filehippo.com/download_firefox/7345/

  • FF 7.0.1 on Mac OSX 10.6.8: I sometimes get the "unresponsive script" dialog box in the top left corner of the screen, so far out that I can see only the bottom right corner of the dialog box. Is there any way of re-centring it?

    FF 7.0.1 on MacOSX 10.6.8 (not this machine!): I sometimes get the "unresponsive script" dialog box jammed into the top left corner of the screen so that only a quarter of it is visible.
    Is there a way of re-centring the dialog box (in particular, when its top edge is off the screen)?
    Thanks!

    There is no way to preserve view preferences.Just remember or annotate the zoom % used in the package.
    You may want to open an MS Connect item asking to add such a feature.
    I can tell you it may not be implemented because a package may be opened on different size monitors.
    Arthur My Blog

  • I've edited my NEF photos in lightroom and have tried to export to a formatted CD. When I try, I have several issues. I either see in the top left corner that the files are ready to go to CD but there is no further instruction or I get the pop up message

    I've edited my NEF photos in lightroom and have tried to export to a formatted CD. When I try, I have several issues. I either see in the top left corner that the files are ready to go to CD but there is no further instruction or I get the pop up message that the files are offline or missing??

    Just for background, in what format are you exporting your images?  Also, are you able to export them to your hard drive in your chosen format?  I haven't tried exporting directly to CD, but if you're able to export to hard drive and copy to CD, that may be one solution.

  • I've lost the orange firefox tab with the arrow, that was in the top left corner: how do I get it back?

    I've lost the orange firefox tab with the arrow, that was in the top left corner: how do I get it back?

    In current Firefox releases (29 and later), that have have the Australis user interface, the orange Firefox menu button has been replaced by the three-bar Firefox Menu button at the far right end of the Navigation Toolbar and this button is always visible, whether you have the menu bar visible or hidden<br>A consequence of this location is that you no longer can hide the Navigation Toolbar
    *There is a star like button to the right end of the search bar on the Navigation Toolbar to bookmark the current web page and a "Show your bookmarks" button next to it to open the Bookmarks in a drop down menu.<br>You can find "Show All Bookmarks" to open the Bookmarks Manager (Library) at the bottom of this drop-down list
    *It is still possible to have the menu bar visible via the right-click context menu on the toolbars to have menus like the Bookmarks menu
    *<br>*If you bookmark a page then "Bookmark This Page" in the Bookmarks menu changes to "Edit This Bookmark"
    See also:
    *https://support.mozilla.org/kb/how-to-make-new-firefox-look-like-old-firefox
    *https://support.mozilla.org/kb/common-questions-after-updating-to-new-firefox
    *https://support.mozilla.org/kb/learn-more-about-the-design-of-new-firefox
    I'm locking this thread. If you still have questions then please create a new thread.

  • I have placed my SIM card into my iphone 5c and have confirmed co with my cellular network provider.However despite numerous reboots I am still getting "No Service" in the top left corner. Please advise

    I have placed my SIM card into my iphone 5c and have confirmed co with my cellular network provider.However despite numerous reboots I am still getting "No Service" in the top left corner. Please advise

    Contact the carrier and troubleshoot the issue.

  • How can i get ipod nano to get the lock icon off the top left corner?

    Hey, my moms ipod nano won`t sync to her computer. Now it has a lock icon in the top left corner and i can`t get it to go away. Can anyone help me?

    I assume you have made sure the hold switch along the top of the Nano is set to Off?
    If none of the 5 R's are able to resolve the issue, it's likely a hardware issue, meaning you'll need to have the iPod serviced/replaced either by Apple or a third party service.
    http://www.apple.com/support/ipod/five_rs/nano2gen/
    B-rock

  • HT1414 if i unlock my iphone 5 from virgin mobile will this get rid of the "virgin" at the top left corner?

    Just about to get a iphone 5 from virgin mobile, the "virgin" in the top left corner is throwing me off, if i unlock it will it go away?

    Welcome to Apple Support Communities
    That will go away if you use your iPhone with another carrier's network, but in that case, you will see the name of that carrier at the top left corner. That means that the Virgin text at the top left corner has nothing to do with having the device locked, but it shows because you are using a Virgin SIM card

  • HT4095 What happens if the genre box goes missing on the top left corner on your iPad? How do I get it back?

    What happens if the genre box goes missing on the top left corner on your iPad?How do I get it back please help me.

    Try quitting iTunes and restart your iPad.
    Go to the home screen first by tapping the home button. Double tap the home button and the task bar will appear with all of your recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner of the app that you want to close. Restart the iPad.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    You can also try a reset if quitting the app doesn't work.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.

  • How do I get the orange firefox button to show up on the top left corner of my page?

    So, I've installed, and reinstalled the new Firefox 4. It seems like only half the features have shown up. For example, I don't have the orange firefox button in the top left corner. I also don't have the button for bookmarks. On every other machine that I've installed firefox 4 on has not had issues like this. I don't know why I'm having issues on my laptop. If there's a way to fix it, I would appreciate it. I don't mind how it is right now, but I do like the cleaner look and the orange firefox button, instead of the buttons that show up now that are labeled: "File, Edit, View, History, Bookmarks, etc."

    * You see the orange (on Linux gray) Firefox button if the Menu Bar is hidden (View > Toolbars > Customize or right-click a toolbar).
    * If you need to access the hidden Menu bar then press F10 or hold down the Alt key to make the Menu Bar appear temporarily.

  • I was logged onto FB and on one of my friends wall. I cannot back out of it, the notifications header that is usually in the top left corner is not there anymore. Anyone know how to retrieve this or get me logged of FB? HELP

    I am logged into facebook on my iphone...I am on a friends status and I am not being able to back out of his status because the "notification" header that should be in the top left corner to back me out of his status is not there. Anyone ever experience this before? I have tried soft reset, shaking the phone and syncing again with my computer.

    Facebook is a webpage but also have several Apps when you ask facebook questions stateing how you access facebook would be beneficial for people IN order to HELP you

  • How do I get rid of this blue circle on the top left corner of my window?

    I had just installed OSX mavericks for my macbook and now whenever I open up firefox there's a weird blue circle in the top left corner of the firefox window.

    The problem appeared today after installing the latest update on MacOS 10.8.5 (which was out for a couple of days/weeks; I don't reboot my system that often). The auto-update of my Firefox is enabled so I don't know exactly when that got upgraded. Current version is 27.0.1. I have the minimalistic theme enabled "Default Mod 28" from http://gpopper.deviantart.com/.
    When I switch to the default theme "Default 27.0.1" from Mozilla, there is no blue circle. When I switch back to the GPopper theme, the blue circle is there again. It is consistently. I would be great to have a Safari-like theme on Firfox, especially for the Bookmarks Toolbar, which is for my preferences too high in the default theme.

  • My Iphone 5s can not connect me to my network. It just says searching in the top left corner for 2 days now.

    Yesterday morning, my phone decided to kick me of my network and not let me back in. In the top left corner, it just says 'Searching...'. I have tried restarting my phone, resetting all settings and resetting network settings and nothing has decided to work for me. I then went to reset my phone but it will not let me log out of 'Find my Phone'. Therefore it did not allow me to reset my phone.
    Please can somebody help.
    Thanks.

    You'll have to unlock the phone in icloud.com/find to be able to get pass the activation lock.
    See also:
    iCloud: Troubleshooting Find My iPhone, iPad, iPod touch, or Mac
    Find My iPhone Activation Lock in iOS 7

Maybe you are looking for