Posted: 24th Sep 2011 16:55
Can anyone spot my mistake here? The idea is that as the viewport moves, the background appears stationary as it follows the viewport. However, the sprite seems to be frozen at 0,0 and won't move. I have the getSpriteX() on screen and it is definitely changing.


+ Code Snippet
    if getSpriteX(gShip) - getViewOffSetx() > 220 and getViewOffSetX() < 1056
        setViewOffset(getViewOffSetx() + 1, getViewOffsetY())
        gBackdropX = gBackdropX + 1
        setSpritePosition(gBackdropSprite, gBackdropX, getSpriteY(gBackdropSprite))
    endif

    if getSpriteX(gShip) - getViewOffSetx() < 260 and getViewOffSetX() > 0
        setViewOffset(getViewOffSetx() - 1, getViewOffsetY())
        gBackdropX = gBackdropX - 1
        setSpritePosition(gBackdropSprite, gBackdropX, getSpriteY(gBackdropSprite))
    endif


The value for the Sprite X value is displayed and moves as expected:

+ Code Snippet
setTextString(gTextDebug, "Sprite X   : " + str(getSpriteX(gBackdropSprite)))
Posted: 24th Sep 2011 18:41
The idea is that as the viewport moves, the background appears stationary as it follows the viewport. However, the sprite seems to be frozen at 0,0 and won't move. I have the getSpriteX() on screen and it is definitely changing.

If the background remains stationary (because it follows the viewport), the values would not change, right?
And, you are adding 1 to the variable 'gBackdropX', which you are retrieving by GetSpriteX (gBackdropX)?
Posted: 24th Sep 2011 23:42
If the background remains stationary (because it follows the viewport), the values would not change, right?


If the Viewport is offset by 1, then the backdrop must be offset by 1 in order to be stationary in the eyes of the player. At least, that's the way I have interpreted the way the viewport works. I actually want it to scroll very slowly,but in order to prove the theory I'm using this 1:1 relationship.
Posted: 25th Sep 2011 1:08
I haven't used the viewport command, but I would have thought if you are moving the viewport like a camera to move around, you would want to keep the back drop at the same place. If you offset it the same as the viewport the backdrop will stay still as you are offsetting it with the viewports movement. The sprite positions will change, but as everything is being offset anyway they will appear stationary.
I think that is the problem anyway.
Posted: 25th Sep 2011 23:31
DVader, that is exactly what I want to achieve - stationary background whilst the foreground moves with the viewport.
Posted: 26th Sep 2011 1:33
If you truly want your background stationary, can't you just lock it to the screen? Or am I missing the point?

And even after you lock it to the screen, you can still move it. At least I think that's the case. Hmmm... maybe just scrolling the U part of the sprite U/V?
Posted: 26th Sep 2011 3:16
Are you sure that gBackdropSprite holds the correct handle?
This quick test works for me:
+ Code Snippet
backdrop = CreateSprite(LoadImage("background.jpg"))
sprite = CreateSprite(LoadImage("test.jpg"))

Do
    Inc (counter)
    If counter Mod 10 = 0
        Inc (bgd)
        SetSpritePosition(backdrop, bgd, bgd)
        SetViewOffset(GetViewOffsetX()+1,GetViewOffsetY()+1)
    EndIf
    SetSpritePosition(sprite, 50, 50)
    Sync()
Loop


The backdrop sprite stays stationary while the foreground sprite slowly slides out of the moving viewport.
Posted: 28th Sep 2011 0:57
Fixed with the new update.
Posted: 9th Oct 2011 3:22
Happy to help Any more issues, remember we are always listening here: http://code.google.com/p/agk/issues/list