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
Developer
magfed
Posts: 37
Registered: ‎09-15-2009
My Device: Not Specified
Accepted Solution

Sprite class analog

Hi everyone.

 

In MIDlets there is a Sprite class, which allows to draw a frame sequences (and other usefull things). 

 

Has a BB API something like that? I've looked through the documentation, but didn't find anything :smileysad:.

Could I use a "classic MIDlet" Sprite class to draw frames on the BB Screen (in paint() method)?

 

Thank you,

magfed 

Please use plain text.
Developer
kumaresan
Posts: 183
Registered: ‎12-17-2008
My Device: 8320

Re: Sprite class analog

First,If you are developing your sprite class in MIDlet , now you want to deploy your MIDlet

 

in BB device you can go to properties --> Application -->project type -- > MIDlet.

 

Then only it will work.

 

Second, if you are creating CLDC Application in BB device , may be can use MainScreen,

 

PopUpScreen,etc for Display Screen View. so here you cant to add Sprite class

 

in this Display view.

 

 

 

 

kums

******************************

Press kudos which the post help you
Please mark posts as solved if you got a solution
Please use plain text.
Developer
magfed
Posts: 37
Registered: ‎09-15-2009
My Device: Not Specified

Re: Sprite class analog

Thanks for your post.

 

I am creating CLDC Application in BB device - no MIDlet.

 

Is there nothing in BB API with the same functionality as the Sprite class? 

Please use plain text.
Developer
kumaresan
Posts: 183
Registered: ‎12-17-2008
My Device: 8320

Re: Sprite class analog

Is no API for like that,

 

But use invalidate() method for repaint the screen.It will help for you.

 

you can try with this.

kums

******************************

Press kudos which the post help you
Please mark posts as solved if you got a solution
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: Sprite class analog

You can use

javax.microedition.lcdui.game.Sprite

 

 in BB app also.

 

 


Press the kudos button to thank the user who helped you.

If your problem was get solved then please mark the thread as "Accepted solution"

 

 

Deepesh Gupta
Please use plain text.
Developer
magfed
Posts: 37
Registered: ‎09-15-2009
My Device: Not Specified

Re: Sprite class analog

Thanks everyone.

 

I've made my own Sprite class. But anyway thanks to everyone for your posts.

 

 

class CMySprite { private Bitmap m_Image; private int m_FrameWidth; private int m_FrameHeight; private int m_XCenter = 0; private int m_YCenter = 0; private int m_CurrentFrame = 0; private int m_FramesCount; /** * Constructor * * @param Bitmap - bitmap is the row sequence of frames * @param int - with of each frame */ CMySprite(Bitmap image, int frameWidth){ m_FrameWidth = frameWidth; m_FrameHeight = image.getHeight(); m_Image = image; m_FramesCount = image.getWidth() / frameWidth; } /** * Set coordinates of the center of frame to be painting on the screen * * @param int - x coordinate of center point if the frame at the screen * @param int - y coordinate of center point if the frame at the screen */ public void setCenterFramePosition(int xCenter, int yCenter){ m_XCenter = xCenter; m_YCenter = yCenter; } /** * Set zero-based number of frame to be painting on the screen * * @param int - zero-based number of frame to be painting on the screen */ public void setFrame(int frameNum){ m_CurrentFrame = (frameNum >= m_FramesCount) ? 0 : frameNum; } /** * Switch to the next frame of the frame sequence. If the * next frame greater than frames count, the next frame is the * first frame. */ public void nextFrame(){ if((++m_CurrentFrame) >= m_FramesCount) m_CurrentFrame = 0; } /** * Switch to the previous frame of the frame sequence. If the * previous frame less than 0, the previous frame is the * last frame. */ public void prevFrame(){ if((--m_CurrentFrame) < 0) m_CurrentFrame = 0; } /** * Paints the sprite frame * * @param net.rim.device.api.ui.Graphics - graphic context. */ public void paint(Graphics g){ g.drawBitmap(m_XCenter - m_FrameWidth / 2, m_YCenter - m_FrameWidth / 2, m_FrameWidth, m_FrameHeight, m_Image, m_FrameWidth*m_CurrentFrame, 0); }};

 Than, at  the paint method of the screen:

 

 

Bitmap myFrames = Bitmap.getBitmapResource("img/frames.png");CMySprite tmpSprite = new CMySprite(myFrames, 100, 100);tmpSprite.setFrame(0);tmpSprite.setCenterFramePosition(50, 50);tmpSprite.paint(g);tmpSprite.nextFrame();tmpSprite.setCenterFramePosition(50, 150);tmpSprite.paint(g);tmpSprite.nextFrame();tmpSprite.setCenterFramePosition(50, 250);tmpSprite.paint(g);

 

 

 

 

 

Please use plain text.
Developer
magfed
Posts: 37
Registered: ‎09-15-2009
My Device: Not Specified

Re: Sprite class analog

Wow, the code is not pretty readable, I don't know why...
Please use plain text.
Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Sprite class analog

magfed,

 

I see you are an old school C++ programmer with your m_ naming conventions.  If you want to bounce ideas about Sprites and anything else relating to gaming (Sounds....this is a pain) on the blackberry, let me know.

Please use plain text.
Developer
magfed
Posts: 37
Registered: ‎09-15-2009
My Device: Not Specified

Re: Sprite class analog

Thank you, RLord321.

You are right - I am C/C++ programmer, but now I have to develop mobile Java projects - hope, it is temporary. C/C++ is more "friendly" for me.

Please use plain text.