Scrolling the tilemap by user movement

edited August 2013 in Development
Hi Selim,

I have a position problem with my player sprite after the tilemap has scrolled. Here is my code: http://lortschi.de/games/bd/
The playground is smaller created as the tilemap. So I can move the tilemap in the opposing direction when the player reached at a certain point on the map. In this case is the 800px mark. In my code is this the scrollStage function at line 196.
The curios problem after the map movement is, that my player sprite position isn't updated by the playground. I try to move my group where the sprite added to simmilar with the tilemap together. But it doesn't helps anymore. After the map movement my player staying on the right place but the playground thinks he has the old position couple of pixels behind them.
I have tryed everything but I couldn't solve this problem. Please help my Selim :)

Thank you in advance!

Comments

  • Oh sorry mistyped, I meant of course: help me and not help my :D
    Ok, anyway is this maybe a bug in the engin, that the added groups and sprites to playground won't be position-updated by tilemap moving?
  • edited September 2013
    Hi,

    I'm not sure exactly if I understand the problem you're describing but since the player is not a child of the tilemap it shouldn't move when you move the tilemap.

    The structure of you DOM looks like this at the moment:

    playground
    -> tilemap
    -> group (player)
    -> rockfordAni
    -> group (exit_door)
    -> exit
    if you want to make the player move along the tilemap you could make it a child of the tilemap:

    playground
    -> tilemap
    -> group (player)
    -> rockfordAni
    -> group (exit_door)
    -> exit
    or put both of them in a group and move the group instead:

    playground
    -> group (view)
    -> tilemap
    -> group (player)
    -> rockfordAni
    -> group (exit_door)
    -> exit
  • Hello Selim,

    oh yes you're right! I created now a toplevel group "view" and put my tilemap and all the other groups in it. The same structure as you mentioned by your 3th example. Now I get everything scrolled. But sry there is a next problem :( After moving the tilemap the playground width wouldn't been calculated new and the end of the playground is somewhere in the middle of the tilemap. If you test the game you will it see. You can't move the player till the end of the area. How can I solve this problem after moving the tilemap?

    Thank you for your help!
  • Can somebody give me a reason for this issue?? Or a way around the problem? I can't carry on still this problem in the gameplay existing. Is this a gamequery problem?

    Thanks for all helps!
  • Hi,

    Sorry I didn't answered you earlier. The only problem I encountered in you game (that look, sound and play very well now) is that once the screen has been scrolled the player can't pass the place where the screen used to end.
    This is due to the following error in your code:
    /**
    * Player Moving Setups
    */

    var player = {
     
    left : function() {
    /* ... */
    },
    right : function() {
    moved_before = 'right'; //determined up/ down ani of Rockford moving
    if(!moving_right) {
    moving_left = false;
    moving_right = true;
    $("#rockfordAni").setAnimation(animations[14]);
    }
    var nextpos = $("#player").x()+32;
    if(nextpos < PLAYGROUND_WIDTH - 32) {
    /* ... */


    At the last line I quoted you can see that you check that the player isn't farther away that the width of the screen where you should really check that she isn't farther away than the width of the level.

    Hopes it solve you problem and don't hesitate to ask if you have more question, I will try to answer them faster !
  • edited October 2013
    aaah yes of course! Thanks a lot, that was the reason for the problem. I don't recognized after the tilemap movement would also be changing the visible playground width in the API. So I got to add the new amount of pixel width to the rest and so the player restriction is farther as now.

    By the way Selim, I have another question. Now is so that on the hidden tilemap areas the animations aren't active. That may couse me a problem in the next level of the game. There will be some anamies and they must act continuously in background.

    Is there currently a possibility to activate the whole animations? Also in the not visible part of the tilemap?
  • there is no way to enable the hidden tiles. They are not simply inactive but not even present at all. But if you have enemies I would recommend not implementing them with tiles but with simple sprites. In you tilemap you could simply leave an empty place or add transparent tile if you want to be able to find their position from the tilemap.

  • Ok, thanks a lot for your help and suggestions! :) As soon as the game is finished, I will here inform you.
Sign In or Register to comment.