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 / Endless scrollable space?

Author
Message
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 6th Jul 2017 21:25
GameMaker makes this very easy, add a background image and set it to tile and the engine takes care of the rest, instant endless scrollable space, how would I go about doing this in AppGameKit?

I have a 1024x1024 seemless background image and I want to present a vast play area so I thinking sprite recycling would probably be best but I'm a little lost in trying to imagine the logic behind it, any pointers?
GameDevGuy
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location:
Posted: 7th Jul 2017 00:28
Hi PartTimeCoder,

The specifics depends on your target screen size, but in summary first figure out how many copies of the background image are needed as separate sprites.

In the image below you need 6. But then thinking about the scrolling, you need double this because an extra row and column is needed. (If you were to slide sprites 1,2,3,5,6,7 around you can see that there will be gaps unless you have the extra sprites as well.)

Then some maths is needed to juggle the position of the sprites once you start scrolling

For example, if the background is moving to the left, a point will be reached where sprites 1 and 5 are completely off screen. At that time they can be positioned to the right of sprites 4 and 8. (In readiness for when sprites 4 and 8 have moved far enough to the left that 1 and 5 will be needed.)

In a similar way, when scrolling to the right, or up and down, it is possible to always ensure that there will be sprites ready to scroll into view.

Of course, the maths is the slightly tricky part, but by setting code that draws the sprites like this, and then experimenting with the scrolling movement, it sort of becomes a lot easier once you start doing it.

easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 7th Jul 2017 00:33 Edited at: 7th Jul 2017 00:37
You just need 2 sprites. Position one of them at 0,0 and the other one at [screen width],0. Each frame, move both sprites left by the same amount, but also check if either of them has moved entirely past the left side of the screen [x<-screen width], if it has, place it so it's exactly at the right-hand side of the other sprite.

There are plenty of ways to do infinite scrolling but this is probably the simplest. It does have drawbacks however. For example because you're movie each sprite by a certain distance each frame (rather than placing the sprites absolutely based on the current player x pos), you can't easily jump backwards or forwards through the level.


Edit: Posted at the same time as the other reply. Mine assumes your background sprites are the exact size of the screen. The technique will still work across multiple screen size, it's just more complicated since you have to adjust the sprite positioned based on a different area (not 0 to screen width)

My Games - Latest WIP - My Website: Immortal.Digital - FB - Twitter
130,000 installs with AppGameKit and counting
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Jul 2017 00:40 Edited at: 7th Jul 2017 00:51
Example project attached to this post. Wasn't sure which direction you planned on scrolling. The example supports scrolling left and right.

Very simple knocked out graphics but that is not the focus anyway so....

Those 1024s in the code should really be a constant definition like IMAGE_WIDTH so you can easily change to different width images. But I threw it together too fast to think about it at the time.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)

Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 7th Jul 2017 00:58
Quote: "Of course, the maths is the slightly tricky part, but by setting code that draws the sprites like this, and then experimenting with the scrolling movement, it sort of becomes a lot easier once you start doing it. "


that's exactly what I am facing I cant visualise the math in less than 200 lines of code! lol, I shall experiment further, I was hoping someone had a pre-made drop in solution

@GarBenjamin & easter bunny, thanks for the input and example, I need a multi directional solution as per GameDevGuy's image to simulate an open world top down space scene, I'll get there in the end.
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 7th Jul 2017 01:12
Check out my refender game. I posted some tutorials and I think some ended up in the newsletter.

The game works over a planetoid landscape which is 8x1024 screens wide and loops around.

One of the main things to think about is the virtual space vs the screen space. GameDevGuys illustration does make the point, but you have wrapping issues to contend with (if you wrap it of course)

1024x1024 is quite a big tile though..

Another concern is that I always use a placement mapping function for this kind of thing.
So, everything in the game is positioned using a routine that works in tandem with the "world" offset. This can also handle the wrap-around issues if needed.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Jul 2017 01:22 Edited at: 7th Jul 2017 01:24
@PartTimeCoder ah sorry about that.

I made an unlimited scrolling tile map engine when I first started checking out AGK2 end of last year. It basically works the way @GameDevGuy illustrates above.

The screen is filled with sprites, multiple layers in fact because the test was a parallax level, and as I recall I had a border of sprites around the entire visible screen.

Well yes thinking about it of course I did because that is needed for the scrolling.

Then it is just a matter of sliding them around as needed. Although come to think of it I may have investigated using the built-in scrolling of the playfield.

At any rate yes multi-directional scrolling there it more to it but it is the same principle. I think it should be doable with only 9 sprites because basically the center sprite will really be the main focus and all of the sprites will never move more than the size of one of the sprites and at that point they will all be reset back to their defaults.

I think maybe look into that built-in scrolling thing. It is ViewOffset or something like that. Basically do a mod 1024 on the X and Y and it should seamlessly scroll in all directions if you have 9 screen size sprites 1 for screen at start and the rest forming border around it all.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Jul 2017 01:50 Edited at: 7th Jul 2017 01:52
Yeah, 9 sprites using SetViewOffset works fine.

You can easily replace SetViewOffset with SetSpritePosition and move the 9 sprites if you prefer.

Unlimited Multi-Directional Scrolling With One Image project is attached to this post.

Move around with Arrow keys or WASD. Speed is adjustable in the constant definitions.

Sorry for the delay.... I spent a little more time trying to make a somewhat more interesting image.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)

Attachments

Login to view attachments
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 7th Jul 2017 02:00 Edited at: 7th Jul 2017 02:04
Quote: "I need a multi directional solution as per GameDevGuy's image to simulate an open world top down space scene"

Ah. Well tbh the technique I gave could work here too. Initially you place all 12 (or whatever number you need) of images. Then move all 12 by the same amount each frame (in any direction). Check each frame to see if any of them have gone over the edge and if so, adjust the position

Here's an example (you can post directly into AGK)

main.agc


Of course, you normally want to move the viewport around with SetViewPosition. I think my code would work exactly the same way for that actually. You would just skip all the sprite moving code, and check if a sprite goes off the edge of the screen relative to the viewport position. It should work automatically... Just a sec I'm gonna try it

Edit: Yep works fine

main.agc

My Games - Latest WIP - My Website: Immortal.Digital - FB - Twitter
130,000 installs with AppGameKit and counting
GameDevGuy
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location:
Posted: 7th Jul 2017 03:10
@easter bunny, simple effective solution. Thumbs up.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Jul 2017 03:26
@easter bunny I missed your post before until I just noticed @GameDevGuy's comment.

Nice work!
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 7th Jul 2017 03:38
Thumbs up to both you guys I thank you very much for your help, easter bunny's solution is a great start for a tiled system, I may expand on this, GarBenjamin's solution is perfect for my immediate need it has simplified my approach somewhat

I did have a go with a 9 tile system it worked for the most part but the further I got into the map it became like a rubic's cube, thanks again for the help.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 7th Jul 2017 07:39 Edited at: 7th Jul 2017 07:42
Since you say it is a top down space shooter, I presume that your texture is a relatively simple starfield so you could get away with a single texture that is repeatable horizontally and vertically.
You can then make this a super-simple task of scrolling the UV texture with SetSpriteUVOffset().

It's a solution that I employed in Floppy Birds in the Small Game Templates thread. In that I only scrolled horizontally but the technique is the same for vertically offsetting too.
Click the link above and you can download the full source code and media to see how it works - it is heavily commented but I'm happy to answer any additional questions.
AGK V2 user - Tier 1 (mostly)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 7th Jul 2017 09:55
Totally agree with Scraggle on this. Set the image to repeat UV using SetImageWrapU and SetImageWrapV which will "tile" the image, and the scroll it around using SetSpriteUVOffset.

Little example:



Nice and light on CPU too
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Jul 2017 11:06
that is clever
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Jul 2017 15:47
@Scraggle and @CJB I agree with @blink0k that is an excellent solution. And one that never even crossed my mind. Too "old school" oriented to think of such things. lol

Anyway great work!
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 8th Jul 2017 06:18
I did consider using the UV method but as I have other things setup in the system such as space stations, planets, asteroid belts and such I did not want to have to move everything based on the UV offset I quickly scraped the idea but it only just dawned on me that I don't have to, I simply move the background image with my ship setting the uv offset to simulate movement.

I think I'll attempt this, will post results.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 8th Jul 2017 07:05
Well one nice thing is this thread will be very useful to all the people in the future who are looking for the same thing. There are a variety of good solutions in here and one of them should match everyone's requirements / preferences.

That's great stuff. Now if there was a thread with several solutions for every possible question... right their server would probably collapse. I was going to say that would be really awesome.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 10th Jul 2017 12:45 Edited at: 10th Jul 2017 12:46
@GarBenjamin, I was using your example and noticed a issue, I place some items way outside the view area but could never reach them as your code loops the view area so once I reached the left edge I would warp in the right (and same for top/bottom), I know that sould have been obvious to me looking at the code but didn't dawn on me till I started building the level.

So, I went with the UV method while moving the background and setting view offset and uv offset in opposite directions, it works pretty well.

GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 10th Jul 2017 16:36
Hey @PartTimeCoder I'm not sure exactly what your requirements were / are and am glad you sorted out a solution that works for you!

I'm guessing you mean you had some sprite objects that were scrolled along with the seamless image using via View Offset and then of course they get reset. That is very true.

There are different ways to handle that... one being to shift all of the object positions at the point of the wraparound (warp as you call it), another being to FixThoseObjects so they do not scroll via View Offset and instead you'd manually need to do that (easiest way would be to not change the world coords for the view and instead wrap the mod around the coords inside the SetViewOffset function), another being to use the hybrid approach you have and so forth.

Actually I think the approach you ended up with is probably the best overall solution!
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Jul 2017 13:03
Instead of moving the background sprite around with the world offset, you could simply fix it to the screen after creating it using:

FixSpriteToScreen(sprBackground ,1)

JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 13th Jul 2017 19:41 Edited at: 13th Jul 2017 22:30
Or you could do something completely crazy and over-the-top ( I honestly wouldn't do it any other way! ), and do something similar to this: It's a scrolling starfield with some added shooting stars to bring the backdrop to life, using two different images. Everything is in modules, so you can easily pick and choose what you want to use or not. Last, if you want the stars to scroll and center around your player ship, just add the players x and y position to both the offscreen check and the screenwrap reposition parts of the UPDATESTARFIELD() function and of course make sure the controller object isn't on auto mode, too easy. Good luck with your game!





SOURCE CODE V1.0 DOWNLOAD



EDIT: Ok, almost done with Version 2.0..now includes random space nebula that flow and morph when interacted with, space is now a multilayered parallax scrolling starfield, a simple player ship with controls, space scrolls with players movement, easy-use animated scifi HUD, and last (which i'm currently working the bugs out of) easy-use radar system that'll pop up in the top left of the HUD.

Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Jul 2017 20:54
That's pretty neat, it really brings the background to life.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 15th Jul 2017 03:00
@JLMoondog ha ha you went all out on your sample. Ini settings file and quite thorough system. Nice work.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 6th Aug 2017 04:18
I find the easiest way is with tiles

The following shows four way scrolling with some modification diagonals aren't much harder
no media required
https://forum.thegamecreators.com/thread/216193

If you want to rotate around a seemless area you may wish to see this thread
https://forum.thegamecreators.com/thread/216392

GOODLUCK
fubar

Login to post a reply

Server time is: 2024-09-30 05:24:57
Your offset time is: 2024-09-30 05:24:57