ArianeSoft - Programming and development for Windows and Windows Mobile :: Forums :: PPL - Pocket Programming Language :: Support
 
<< Previous thread | Next thread >>
side scroller
Moderators: kornalius, bmanske, PointOfLight
Author Post
Heinz
Mon May 05 2008, 04:53pm

Registered Member #114
Joined: Tue Oct 24 2006, 01:40pm
Posts: 202
I have a problem with a simple side scroller - similar to the scroll.ppl demo from PPL. When the background scrolls I would like to trigger certain actions at certain positions and I thought, that with OriginX I could get the position of the scrolling background bitmap.
However if the figure walks to the end of the 2000 pixel wide background the OriginX-Parameter has a value of 4395 pixels. I then tried to divide the OriginX value by the appropriate value, so that I get at the end the 2000 pixels, but unfortunately this didn't work either (the necessary correction seems not to be linear over the entire distance).
So I guess my idea with OriginX is the wrong approach to get the position of the scrolling background graphic, but how could I do it properly?

regards,
Heinz
Back to top
zehlein
Tue May 06 2008, 02:32am

Registered Member #30
Joined: Tue Sep 12 2006, 03:00pm
Posts: 449
If you want to know the the position of your walking figure in relation to the underlying background, why don't you use SpriteX() ? I would handle it this way (PseudoCode):

x=SpriteX(Figure)
FigureAt=x mod SpriteWidth(BackGroundSprite)

FigureAt now should hold the Figure's X-Position in relation to the background sprite.

Edit: Maybe it's a good idea to TextOut those x and FigureAt values on the screen to understand how they relate to each other!?

[ Edited Tue May 06 2008, 02:35am ]

There is a crack, a crack in everything. That's how the light gets in. (L. Cohen)
Back to top
Heinz
Tue May 06 2008, 08:23am

Registered Member #114
Joined: Tue Oct 24 2006, 01:40pm
Posts: 202
Hi Zehlein,

thanks a lot for the hint! I have tried it, but it seems, that SpriteX gives the position of the sprite relative to the screen and not the background (i.e. since the figures stays always in the middle of the screen, when the background scrolls by, the SpriteX coordinate stays the same all the time).
I have also tried to check the SpriteX for the background (in the hope that it might change, when the background scrolls relative to the screen), but it stayed constant as well


regards,
Heinz
Back to top
zehlein
Tue May 06 2008, 03:45pm

Registered Member #30
Joined: Tue Sep 12 2006, 03:00pm
Posts: 449
Ok, I think I got it. Make b$ and pillar$ global and replace the whole WM_PAINT section with:
      //  Render all loaded sprites on screen.
      RenderSprites;
      // Output some text.
      x$ = (OriginX * SpriteAutoOffsetX( pillars$)) mod SpriteWidth(pillars$);
      x$ = x$ + SpriteX(mario$);
      g_textout(NULL, "pillars: "  + x$ + " "  + SpriteAutoOffsetX(pillars$) , DVT_CENTER, 0, 2, g_rgb(128, 128, 128) );
      x$ = (OriginX * SpriteAutoOffsetX( b$)) mod SpriteWidth(b$);
      x$ = x$ + SpriteX(mario$);
      g_textout(NULL, "wall: " + x$ + "  " + SpriteOffsetX(b$) , DVT_CENTER, 0, 14, g_rgb(128, 128, 128 ));
      g_textout(NULL, "Mario offset: "  + SpriteX(mario$) , DVT_CENTER, 0, 26, g_rgb(128, 128, 128 ));
      g_textout(NULL, "OriginX="  + OriginX, DVT_CENTER, 0, 38, g_rgb(128 , 128, 128));


The first line on the screen shows marios position relative to the pillar bitmap, the second line relative to the wall bitmap.

There is a crack, a crack in everything. That's how the light gets in. (L. Cohen)
Back to top
zehlein
Tue May 06 2008, 04:32pm

Registered Member #30
Joined: Tue Sep 12 2006, 03:00pm
Posts: 449
Sorry for the double-posting, but the shot was to quick and didn't handle marios position on the screen correctly. Second try (this only works for values OriginX>0; I'm too lazy to implement it for negative OriginX values ):

    WM_PAINT:
      //  Render all loaded sprites on screen.
      RenderSprites;

      // Output some text.
      x$ = (OriginX * SpriteAutoOffsetX( pillars$)) mod SpriteWidth(pillars$);
      if (x$ + SpriteX(mario$)  > SpriteWidth(pillars$))
        x$ = x$ - SpriteWidth(pillars$)  + SpriteX(mario$);
      else
        x$ = x$ + SpriteX(mario$);
      end;
      g_textout(NULL, "pillars: "  + x$ + " "  + SpriteAutoOffsetX(pillars$) , DVT_CENTER, 0, 2, g_rgb(128, 128, 128) );
      x$ = (OriginX * SpriteAutoOffsetX( b$)) mod SpriteWidth(b$);
      if (x$ + SpriteX(mario$)  > SpriteWidth(b$))
        x$ = x$ - SpriteWidth(b$)  + SpriteX(mario$);
      else
        x$ = x$ + SpriteX(mario$);
      end;
      g_textout(NULL, "wall: " + x$ + "  " + SpriteAutoOffsetX(b$), DVT_CENTER, 0, 14, g_rgb(128, 128, 128));
      g_textout(NULL, "Mario offset: "  + SpriteX(mario$) , DVT_CENTER, 0, 26, g_rgb(128, 128, 128 ));
      g_textout(NULL, "OriginX="  + OriginX, DVT_CENTER, 0, 38, g_rgb(128 , 128, 128));


There is a crack, a crack in everything. That's how the light gets in. (L. Cohen)
Back to top
Heinz
Wed May 07 2008, 03:52pm

Registered Member #114
Joined: Tue Oct 24 2006, 01:40pm
Posts: 202
Dear Zehlein,

thank you so much for your efforts!!!! That's exactly what I needed!

thanks,
Heinz

regards,
Heinz
Back to top
 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System