09-23-2009 09:25 AM
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
.
Could I use a "classic MIDlet" Sprite class to draw frames on the BB Screen (in paint() method)?
Thank you,
magfed
Solved! Go to Solution.
09-23-2009 09:44 AM
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.
09-23-2009 09:51 AM
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?
09-23-2009 10:01 AM
Is no API for like that,
But use invalidate() method for repaint the screen.It will help for you.
you can try with this.
09-23-2009 10:38 AM
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"
09-23-2009 11:19 AM
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");CMySpri
te tmpSprite = new CMySprite(myFrames, 100, 100);tmpSprite.setFrame(0);tmpSprite.setCenterFram ePosition(50, 50);tmpSprite.paint(g);tmpSprite.nextFrame();tmpSp rite.setCenterFramePosition(50, 150);tmpSprite.paint(g);tmpSprite.nextFrame();tmpS prite.setCenterFramePosition(50, 250);tmpSprite.paint(g);
09-23-2009 11:21 AM
09-23-2009 12:34 PM
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.
09-24-2009 05:20 AM
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.