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 Studio Chat / Best way to make sprite move while background is scrolling

Author
Message
2D Analyst
AGK Developer
15
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 6th Oct 2019 22:29
I have game with scrolling background. If the character move left or right, the background scroll. Now, I want to place fixed item in the game and I want the item to scroll only when background scroll. Is there a math formula or function that will ensure the sprite will move along with background scroll?

Background scroll is float value and I understand that sprite position are integers. I'm doing trial and error and plug in a number and it looks okay. The sprite item scroll with background scroll, but it's not really perfect.

I was wondering if anyone came across this before?

Scraggle
Moderator
16
Years of Service
Recently Online
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 7th Oct 2019 07:42 Edited at: 7th Oct 2019 07:44
Quote: "I understand that sprite position are integers. "

Why do you understand that? Nobody else does.

Use floats.
Sprite positions don't have to be integers.
houndog66
1
Years of Service
User Offline
Joined: 1st Mar 2019
Location:
Posted: 7th Oct 2019 19:00
is this the sort of thing that you mean?



hope it helps anyway!

Attachments

Login to view attachments
Xaby
FPSC Reloaded TGC Backer
12
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 8th Oct 2019 15:07
How would you scroll two or more layers of backgrounds for parallax effects? Depth effect, or 3Dish effects.

I guess, it would be very CPU heavy, to change the Sprite positions of all "tiles" on one layer of background.

Is it possible, to group them in some way? Is there a Background-Flag or so? Like the FixSpriteTo...
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 8th Oct 2019 21:45
You could use GetWorldX/YFromSprite(). It would return the world co-ordinates of a pixel in your background image.
2D Analyst
AGK Developer
15
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 9th Oct 2019 04:53
Thanks. These are good information. I ended up using sprite offset based on hero speed multiple by 2, which gives an illusion of hero walking pass items without the need to code the game tile base.

When I get more areas, items and monsters created, I’ll post some screen shots.

Login to post a reply

Server time is: 2020-03-28 15:42:53
Your offset time is: 2020-03-28 15:42:53