Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Moving Sprite By Grid

Author
Message
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 2nd Dec 2018 13:01
Hello Community,

Can anyone help me to understand how can I move a sprite by mouse but by grid? Let's say 5x5?

It's something about getting the mouse position and detect when it gets over a certain value and then position the sprite to the mouse?

Thank you!
www.alexmatei.com

The author of this post has marked a post as an answer.

Go to answer

Bored of the Rings
User Banned
Posted: 2nd Dec 2018 13:55
There are several ways of doing this, am out at moment but if no one else helps before I get back to you, I can set out some logic you can apply.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
puzzler2018
User Banned
Posted: 2nd Dec 2018 13:58
Im currently working on an ole classic 2D game - which works like map tiles of a 16x9 grid

https://forum.thegamecreators.com/thread/223354

Hope this helps too
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 2nd Dec 2018 14:05
This post has been marked by the post author as the answer.
figure out the width and height of each grid cell in pixels. Then to determine which grid coordinate you are located in, just use gridx = floor(x/cellwidth) and gridy = floor(y/cellheight). To get the upper-left corner coordinate of a grid cell, just multiply the result by the cell height/width. cellx - gridx * cellwidth and celly = gridy * cellheight

example using a cell size of 40x40
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 2nd Dec 2018 21:02
Thank you guys! You helped me a lot, again! A beer to all!
www.alexmatei.com

Login to post a reply

Server time is: 2024-04-20 16:43:10
Your offset time is: 2024-04-20 16:43:10