Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
MC2011
Posts: 14
Registered: ‎04-14-2011
My Device: 9700

How do i do simple 2D animation on a canvas

Hi,

 

I am new to blackberry development and i need to complete and urgent assignment, i have looked around and i dont see much material to point me in the right direction, or some just is a little confusing.

 

I need to split the screen into 2 the bottom half will contain a text field for input and a button, the bottom half will cover about 30% of the screen and the top half the 70% of the screen.

 

On the top half i want to be able to do some 2D rendering in the sence that i want to draw a square for example and move it around smoothly using a rendering loop.

 

What components of the api should i look into to accomplish this task ? It has to be on version 5.0

 

Thanks in advance.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How do I do simple 2D animation on a canvas

Welcome to BlackBerry and the forums.

 

In this case, what you will need to do is put a Bitmap in the top 70% of the screen (you will need to create this dynamically to match the screen size.  Then you will need to create an animation Thread that draws the moving image, image at a time.

 

This same sort of process is used to draw animated gifs in the following KB article:

http://supportforums.blackberry.com/t5/Java-Development/Display-an-animated-GIF/ta-p/445014

 

I think this KB article will help you get what you need to do sorted out. 

Contributor
MC2011
Posts: 14
Registered: ‎04-14-2011
My Device: 9700

Re: How do I do simple 2D animation on a canvas

Hi, What i want to do on the top half is draw primitives like a square using the graphics library if that is the correct one to use for 2D graphics. Could you advise me a bit about this, i want to be able to draw at coordinates x,y also be able to manipulate it to rotate it and move it around smoothly using a rendering loop(like in opengl) and also change its size by defining new width and height from text boxes on the bottom 30% of the screen.

 

Can you tell me which library's i need to use so i can read up on them? I'm a bit lost. I've been reading about canvas and graphics but im not sure what fits my needs best.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How do I do simple 2D animation on a canvas

Sorry I can't help with the primitive drawing.  Have a look at all the Graphics methods (make sure you use the Blackberry graphics object not the Modlet one).  Take the code from the KB article, and replace the graphics drawBitmap, with whatever you want to do.  Start by just painting a circle and move it each time the Thread goes round the loop.  Do a bit of this, and i am sure you pick up a lot of what you need to do.