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 / [AGK] Attaching an sprite to a sprite grid

Author
Message
nonom
7
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Picking mushrooms
Posted: 21st Apr 2018 20:10
I've a moving sprite in a board, but to be precise I would like to fill the gap when the up,down,left,right key is released so the sprite can be adjusted to the grid.

I had a few ideas substracting the hit part and/or ... a) apply any tweening function? b) custom movement?

I did a graphic explaining the idea, basically i need to know the size of the red line.



Im trying to do this approach. Any other idea? Feedback is welcome.

It's related with https://forum.thegamecreators.com/thread/221978 where I'm adding the player movement
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Apr 2018 13:45
So you want to snap the sprite to align with the grid?

My code assumes the sprite's origin is its center.



To look correct, you'll want to snap the sprite to whichever grid square the center of your sprite falls into. Visually, it'll just make more sense to the user that way. My code gives a solution to the illustration, but I'm assuming that line could be on any of the 4 sides around the sprite? To know which distance you need to calculate, look at where the center of the sprite is in relation to the center of that grid square. You picture shows it right of center. If it's left of center than you'll be calculating the right edge of the sprite from the right edge of that grid square. Same rule applies for vertical distance.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
nonom
7
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Picking mushrooms
Posted: 22nd Apr 2018 18:12
I have the origin in the default sprite offset, so I'll move to the center and will try this approach.

Phaelax wrote: "To look correct, you'll want to snap the sprite to whichever grid square the center of your sprite falls into. "


It sounds like what I'm looking for, many thanks Sir.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 22nd Apr 2018 21:36
What adds a nice effect, when you have the grid x.y positions start a tween and make the sprite glide into its new grid location rather than snapping
nonom
7
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Picking mushrooms
Posted: 22nd Apr 2018 23:10
PartTimeCoder wrote: "What adds a nice effect, when you have the grid x.y positions start a tween and make the sprite glide into its new grid location rather than snapping "


I'm having fun experimenting , thanks for the tip

Login to post a reply

Server time is: 2024-11-23 21:26:03
Your offset time is: 2024-11-23 21:26:03