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 |
| ||
Registered Member #114 Joined: Tue Oct 24 2006, 01:40pmPosts: 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 |
| ||
Registered Member #30 Joined: Tue Sep 12 2006, 03:00pmPosts: 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 |
| ||
Registered Member #114 Joined: Tue Oct 24 2006, 01:40pmPosts: 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 |
| ||
Registered Member #30 Joined: Tue Sep 12 2006, 03:00pmPosts: 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.
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 |
| ||
Registered Member #30 Joined: Tue Sep 12 2006, 03:00pmPosts: 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:
There is a crack, a crack in everything. That's how the light gets in. (L. Cohen) | ||
Back to top | | ||
Heinz |
| ||
Registered Member #114 Joined: Tue Oct 24 2006, 01:40pmPosts: 202 | Dear Zehlein, thank you so much for your efforts!!!! That's exactly what I needed! thanks, Heinz regards, Heinz | ||
Back to top | | ||