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 / SetViewOffset() and looping world

Author
Message
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 8th Mar 2013 00:02
Just trying to decide if using setviewoffset() will work OK if I have a world (e.g. 8 screens wide) and I want to loop around to the start again when I've traversed 8 screens.

Is there an effective way to clamp up the end/beginning loop of your world when using setviewoffset() ?

I could do this myself by tracking *everything* but setviewoffset() makes things easier, what with FixSpritetoScreen() etc.

If I was looping graphics like this, I'd have an extra screen's worth (e.g. screen 9) which was a duplicate of screen 1 and flip over at the edge of screen 8.

Doesn't work so well if you've got enemies, bullets etc. going over the screen threshold...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2013 10:29
This is definitely possible but you will have to check the possition of objects and duplicate them near the edge of the loop.


this.mess = abs(sin(times#))
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 8th Mar 2013 12:31
You could also move the world location of the rooms and simply keep everything else where they are.


Demo 3 is out now!
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 8th Mar 2013 19:31
You might be able to scissor it - that would save moving everything but the offset.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 8th Mar 2013 20:16
The problem is the wrap. I'd have to duplicate sprites where they cross over screen 8, as Baxslash said. Quite a bit of management.

Scissoring would still be required at the right of screen 8 and left of screen 1, but this would leave an (overlapping) sprite on the screen which was made up of 2 sprites potentially. Also some jiggery-pokery on handling the wrap with the offset.

The only other option (as I see it) is to track every object in the game and reposition them accordingly. This would make sense as I could deal with the "offscreen" ones in the same iteration. Still, plenty of challenges then

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 8th Mar 2013 21:03
Why not move room 1 to the end of room 8, and then room 2 to the end of room 1 etc. Wouldn't that work?


Demo 3 is out now!
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 8th Mar 2013 21:09
It's not rooms per-se. Think Defender, where you scroll about the exterior of an asteroid or planet.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 8th Mar 2013 21:46
Ah, I see. Then the easiest solution might be to not use SetViewOffset at all. Keep the player in the center of the screen and move everything else. But if you are using the built in collisions then this might not work or be efficient.


Demo 3 is out now!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Mar 2013 16:42
Marl has the best solution by far, check if your view offset is over the edge of the world and use set scissor to draw the first side of the screen, then use set scissor again to draw the other half. You still have to draw some objects twice when they overlap or by cleverly using drawSprite after rendering the background for all ships etc but it would be the fastest solution can imagine.


this.mess = abs(sin(times#))
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 10th Mar 2013 17:15
I ditched the setviewoffset. It got much more messy considering I would need to loop around the other way.

In the end, it's easier to track everything and apply the world offset to the x co-ordinate. The trick is to have a buffer "screen" at each extreme of the "world". I really didn't like the idea of duplicate drawing (potentially a sprite could be made up of 2 halfs of 2 different sprites!)

I have a world 8 screens wide (plus 1 overlap screen at each end)

To wrap it I have to do the following:

if you are >screen 6, reposition items that are on screen 1 to screen 8. When you hit screen 8, reset pointer to screen 1

Similar behaviour for going the other way.

@Digital: Why your concern over built in collisions?

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 10th Mar 2013 19:25
Quote: "@Digital: Why your concern over built in collisions?"


I'm not too familiar with the collision system so I could be wrong here. But I recall posts about slowdowns or problems when moving around static objects or something. If you use SetViewOffset then you can make the level out of static objects that doesn't move around and I believe that should be faster. Of course, if you don't use static objects at all it wouldn't matter.


Demo 3 is out now!
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 13th Mar 2013 00:22
Well, I ditched SetviewOffset() so I guess no worries then?

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 13th Mar 2013 08:26
That's the opposite of what I meant.


Demo 3 is out now!
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 13th Mar 2013 09:44
Not using SetviewOffset() means I don't need to use fixed sprites either.

Login to post a reply

Server time is: 2024-05-03 08:32:09
Your offset time is: 2024-05-03 08:32:09