Moving a Tile/TileContainer

Hello,

I’m making a simple animation using TileContainer and Tile classes and move it on the screen. Each frame is loaded and displayed on the screen using the Tile class and all the animations are grouped in a TileContainer.

var sprite : TileContainer;

sprite = new TileContainer();
sprite.x = x;
sprite.y = y;

The x and y variables are updated to move the animation on the screen.

2

The problem I’m facing is that the sprites are cut after they reach a position on the screen.

I also tested the same thing with the example project “AnimatedTilemap”, in the update function of AnimatedTile, I just modified the x parameter of the element.

    public function update ():Void 
    {
       if (frames != null && frames.length > 0) 
       {
    			var currentTime = Lib.getTimer ();
    			var timeElapsed = currentTime - startTime;
    			
    			var totalDuration = timeElapsed % loopDuration;
    			var frameCount = Math.round (totalDuration / frameDuration);
    			var frameIndex = frameCount % frames.length;
    			
    			id = frames[frameIndex];
    			
                        //This is what I changed
    			x += 0.1;
    			
    		}
    		
    	}

And the result is the same:

1

I think that the limits where those images are being cut are determined by the size of the Tilemap.

What’s the best way of moving an image freely on the screen using these classes without being cut?

Thank you in advance.

Can you set tilemap.width and height to the size of the window?

Yes, if I do that the area is bigger. Do I have to set the size of each tilemap to the size of the level? Thank you!

Yes, I think that would work :smile:

1 Like