cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a animated image rotate around the z-axis

dvp
Associate II

I have an animated image, and I want to make it rotate around a circle. I assume I need to use a container and somehow integrate the TextureMapper into it, but I’m not sure how to do that.

1 ACCEPTED SOLUTION

Accepted Solutions
JohanAstrup
ST Employee

Hello @dvp.

Yes, you can draw the animated image to a dynamic bitmap, and then use it in a texture mapper. This can be achieved by using a cacheable container or by calling drawToDynamicBitmap().

However, depending on your application, a simpler approach might be to manually implement the animated image, as this can be done quite easily. Then, you set a new bitmap for the texture mapper every x ticks. Remember that calling setBitmap() on a texture mapper resets the texture mapper properties according to the input bitmap. Therefore, you must save the properties before setting the new bitmap and reapply the properties after setting the new bitmap.

You can achieve that by implementing something similar to this in handleTickEvent():

// Update animated image
if (!(tickCount % ANIMATION_INTERVAL))
{
	// Save texture mapper properties and invalidate content
	...

	if (textureMapper.getBitmapId() == LAST_ANIMATION_BITMAP_ID)
	{
		textureMapper.setBitmap(FIRST_ANIMATION_BITMAP_ID);
	}
	else
	{
		textureMapper.setBitmap(textureMapper.getBitmapId() + 1);
	}

	// Set texture mapper properties and invalidate content
	...
}


Best regards,
Johan

View solution in original post

1 REPLY 1
JohanAstrup
ST Employee

Hello @dvp.

Yes, you can draw the animated image to a dynamic bitmap, and then use it in a texture mapper. This can be achieved by using a cacheable container or by calling drawToDynamicBitmap().

However, depending on your application, a simpler approach might be to manually implement the animated image, as this can be done quite easily. Then, you set a new bitmap for the texture mapper every x ticks. Remember that calling setBitmap() on a texture mapper resets the texture mapper properties according to the input bitmap. Therefore, you must save the properties before setting the new bitmap and reapply the properties after setting the new bitmap.

You can achieve that by implementing something similar to this in handleTickEvent():

// Update animated image
if (!(tickCount % ANIMATION_INTERVAL))
{
	// Save texture mapper properties and invalidate content
	...

	if (textureMapper.getBitmapId() == LAST_ANIMATION_BITMAP_ID)
	{
		textureMapper.setBitmap(FIRST_ANIMATION_BITMAP_ID);
	}
	else
	{
		textureMapper.setBitmap(textureMapper.getBitmapId() + 1);
	}

	// Set texture mapper properties and invalidate content
	...
}


Best regards,
Johan