Jump to content

Weirded out by Tilesprite behaviour


Recommended Posts

Hello fellas,


I've created a simple tileSprite that repeats:

hangarbg = game.add.tileSprite(0, ((window.innerHeight-hangarbgHeight)/2), window.innerWidth, 600, "hangarbg");hangarbg.tilePosition.x = Math.round((window.innerWidth-gapx)/2);layerBg.add(hangarbg);

and then attempt to control it via keyboard:

keyleft.onDown.add(function(){   tl = game.add.tween(hangarbg.tilePosition).to({ x: hangarbg.tilePosition.x+517 }, 500, easingX).start();});

... this works well, but the background goes out of sync.
What I need it to do is for the tile to fall always in the same exact place.


Unfortunately on keypress the tilePosition.x might be somwhere within the tween and so the new position gets calculated in the wrong way.


My next thought was then to add a set of coordinates and have them tween to each one of them (instead of using relative positioning), but tween behaves really weirdly:

keyleft.onDown.add(function(){   currentship--;   newDest = -517*currentship;   tl = game.add.tween(hangarbg.tilePosition).to({ x: newDest }, 500, easingX).start();});

This calculates the coordinates correctly but the tween always seems to start from zero.


So on each keypress it goes:


0 -> -517

0 -> -1034

0 ->  -1551


I don't really know how to tackle this.

Any ideas?



Link to comment
Share on other sites

On a further notice if I log the tileSprite.position.x on keypress it is always zero (only if the tween is allowed to complete without further keypresses) even if it's tweened.

If I interrupt the tween with other keypresses the numbers start to change.



The mechanics work with normally positioned sprites, so I might just revert to using sprites.



Solved by using sprites.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...