Analog Sprite class

Hello world.

In MIDlets there is a Sprite class, which allows to draw a sequence of images (and other useful things).

At a BB API something like that? I looked through the documentation, but found nothing .

Can I use a MIDlet 'classic' class Sprite to draw pictures on the screen of BB (in object method)?

Thank you

magfed

Thank you all.

I made my own Sprite class. But anyway thank you all for your messages.

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);    }};

That, to the paint of the display method:

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);

Tags: BlackBerry Developers

Similar Questions

  • Confused about the extension of the Sprite class

    Howdy-

    I learn programming with object oriented ActionScript and am confused about the class Sprite and OO in general.

    My understanding is that the Sprite class allows you to group a set of objects that you can manipulate all the objects at the same time.

    I explored the Open Flash Chart code and note that the main class extends the Sprite class:

    Base/public class extends Sprite {}

    What this lets you do?

    Also, on a related note, how to draw, say, a line once I extended?

    Without extend Sprite I could write:

    var graphContainer:Sprite = new Sprite();

    var newLine:Graphics = graphContainer.graphics;

    ...

    And it works very well. Once I have extend the Sprite class, I'm lost. How can I modify this code so that it still draws a line? I tried:

    var newLine:Graphics = this.graphics;

    My understanding is that since I extend the Sprite class, I should still be able to call its method chart (or property? I have no idea). But, he screams at me, saying "1046: Type was not found or is not a constant of compilation: graphs.»

    A number of things.

    First of all, I would not use this approach in your table constructor. Setting the width and height only makes sense if you adjust the width and height of the existing content, and the table (Sprite) does not at this time here. If you want to give the table a 'size', you could do it like this:

    public function Chart (width: Number, height: Number) {}
    This.Width = width;
    This.Height = height;
    put in a background invisible to this size:
    this.graphics.beginFill (0,0);
    this.graphics.drawRect (0,0,width,height);
    }

    There are other ways, including putting in a form or a Sprite of child as a child for the background so that clear will not erase the background of the chart. This way you could have properties for the background in your table class and update the background as a child DisplayObject instance... a few ideas to think to...

    Then, after that, your chart should be functional...

    Then back in your scenario, you could do this:

    import graphics. Table;

    Stop()

    var myNewChart:Chart = new Chart (300,200)
    myNewChart.render ();
    addChild (myNewChart)

  • game focusing on the sprite class

    Hi, I'm tryin to set global focus to a specific class that already exists on the scene, after that I deleted a contextual dialog box on the screen. I pass the name of the class that was on the scene before the pop-up dialog box is displayed in the string to the popup class.

    If public void PopupMenu(pClass:String)

    Once I removed the pop-up dialog box, I want to restore developed in the previous class, so it can accept events key again.

    How would I set the focus to an instance of an object on the stage. Currently, I have something like this:

    Main.mainStage.focus = (InteractiveObject) (getDefinitionByName (prevClass));

    but he returned this error: TypeError: Error #1034: Type coercion failed: cannot convert com.cox::IdleScreen$ in flash.display.InteractiveObject.

    My IdleScreen class extends sprite, which is definitely on a higher level than InteractiveObject in the diagram to display objects. How can I set focus to this class on the stage?

    I know it can be focused because I can do Main.mainStage.focus = this inside of the class and it works...

    Mount the DisplayObject to InteractiveObject.

    Main.mainStage.focus = Main.mainStage.getChildAt (2) as InteractiveObject;

  • Sprite class problem

    Gives an error.
    See the code provided herewith.
    JST want to draw this sprite and animate.
    Thank you very much

    You need to add it to the displayList and do that she should be wrapped in a UIComponent:

  • The label on the top of the Sprite event management

    Hi everyone, it's more of a general question of Actionscript, but Google does offer all the answers.

    So I made a custom component, element that extends the Sprite class. I draw things on the graphics in this class and then I add a Label to display text.

    In another class, where I create instances of the previous class, I add an EventListener for MouseEvent.Click.  In this function, there is this line:

    selectedElement = Element(event.target);
    

    In short, I want the variable selectedElement to contain the element on which click it. But I ran into problems, event.target is not always an instance of my class. If I click where the label is, event.target is a Label.

    How can I organize if click anywhere on my element, in particular on the label, it's the element of class that dispatches an event and not on its label. I think I need to intercept events of labels in some way, but no idea how to do this.

    Thank you in advance.

    Too bad, in the event class stopPropagation method has been what I was looking for.

  • Table of sprite individual addEventListener

    Hi, I ran into a problem of its too obvious or not many people meet because I can't seem to find a solution online!

    The problem is I have table of sprite - 10 of them - and I need to save them all at a click event that changes color from black to white sprite.

    However, I do not want to write:

    a[1].addEventListener(MouseEvent.CLICK, change1);
    a[2].addEventListener(MouseEvent.CLICK, change2);
    a[3].addEventListener(MouseEvent.CLICK, change3);
    ... etc
    

    Because they are all supposed to do the same thing (changing color from black to white), is there a way for me to use a single click event 'change' and at the same time know that click event demand comes from knowing that 'a', the user clicked?

    Please help me!

    I just assumed that you created your own class which extended the Sprite class, and you called it YourSpriteClass. In your case, your code should be:

    c = new Array();
    for (var i:int = 0; i < 10; i++)
    {
        c[i] = new Sprite();
        c[i].graphics.beginFill(0x000000);
        c[i].graphics.drawRect(50 + i*20, 50 + i*20, 30, 30);
        c[i].graphics.endFill();
        c[i].addEventListener(MouseEvent.CLICK, change);
    }
    
    public function change(event:MouseEvent):void
    {
        var source:Sprite = event.target as Sprite;
            //Code here!
    }
    

    You can also use

    public function change(event:MouseEvent):void
    {
        var source:Sprite = Sprite(event.target);
            //Code here!
    }
    

    The only difference is that the variable source in the first case will be nil when event.target is not a Sprite (like when you assigned the EventListener to something else, as well) and the second solution will throw a TypeError.

  • Difference between Sprite and MovieClip...

    Hi guys,.

    Please can you tell me what is the difference between Sprite and MovieClip?

    Thank you

    JaxNa

    1. a movieclip is a leprechaun on steroids.

    2. a movieclip has a timeline, a sprite does not work.  who has major implications on the properties, methods, and events including a movieclip and a sprite does not.

    3. the movieclip class is dynamic (that is to say, you can add properties), the sprite class is not.

  • custom/sprites forms with code, where to start?

    Hello


    I want to start building forms pre-build, like a star, cross, heart and even more with the code.


    Does anyone know if there is already something like this? A library with custom sprites or forms?


    And can we establish these graphics that extends the sprite class or form? I read that the forms would be
    be the best for performance?

    Kind regards
    Chris.

    Use google to search.

    I know there is public php code for certain forms and the code is not very different for actionscript.

    Use the forms.  There is not much difference, if it is, in performance, but you do not use any of the properties/methods of the sprite class then you can also use the shape class.

  • onEnterFrame within a class

    I don't have a problem as much as just a lack of understanding:

    Question: Will I run into any problems using onEnterFrame within a class? I know that onEnterFrame events can replace each other if they are written in a dynamic way, but I don't know how this effects classes...

    In addition, onEnterFrame is an event of the class movie no clip?... how this same question...? What happens if I declare an event inside a method inside my class onEnterFrame: it'll still work? It will affect the clip hence the class.method is called?

    Sigh... I hope you get the idea of what I'm going to have trouble enter. Please explain all the concepts that I seem to be missing. I'm new to classes - thank you for your help.

    > Question: will I run into any problems using onEnterFrame within a class?
    Laughing out loud
    > Also, onEnterFrame is an event of the movie no clip class... how this same question...?
    Lol here is a brief explanation of how it works.
    First of all, a class is a custom object. Don't think of a class as a bunch of code, it's an object with its own properties and methods. So, when you say: "what happens if I declare an event inside a method inside my class onEnterFrame: will it still work?" you think: "there is no timetable." Yes, there is. When you declare:

    private var my_mc:MovieClip;

    you save the functionality of the MovieClip class in my_mc. Therefore, my_mc will be a timeline and all other properties and methods of the MovieClip class. (In comparison: usually you don't have all the features of the MovieClip class, so AS3 gives us the Sprite class which is a basic implementation of a movieclip and who saves overhead).

    In a method, you can use:

    private void mover(target:MovieClip):Void {}
    target.onEnterFrame = function (): Void {}
    This ._x += 2;
    };
    }
    passing the my_mc mover of function as a parameter. If at some point you want to stop the onEnterFrame you delete just as you would use it in the code on the timeline.

    Once again. The most important thing to understand is that a class is not a bunch of code, it is a (custom) object with its own properties and methods.

  • How to add a component to sprite at the request

    Hello
    In my application, I use a custom component that extends the Sprite class. I add this component to the application as < local: mySprite width = "500" height = "300" / >, but it's to show the following error on the application runs;

    Type coercion failed: cannot convert mySprite@129be5e1 to mx.core.IUIComponent.

    How can I overcome this problem, if suggestions please reply.

    Thank you.

    Anything you add to the display of the application list must implement IUIComponent. Wrap the sprite in a UIComponent or UIMovieClip.

  • How to move to a new page on the click of a button?

    I use actionscript to develop a simple application and I'm new to application development. I don't know how to move to a new page on the click of a button. I need to go back to the old page as well. Kindly help me. The date deadline is almost.

    Welcome to the Forums Supprt.

    If you create your view that the enlargement of the Sprite class, you need to use addchild(), to remove the screen use removechild().

    // to add
    var sp : Sprite = new Sprite() ;
    addChild(sp) ;
    
    //to remove
    removeChild(sp) ; 
    
  • Pinch gesture scaled

    private function onGesturePinch(e:TransformGestureEvent):void{
                    var pinchMatrix:Matrix = this.transform.matrix;
                    var pinchPoint:Point = pinchMatrix.transformPoint(new Point((this.width/2), (this.height/2)));
                    pinchMatrix.translate(-pinchPoint.x/2, -pinchPoint.y/2);
                    pinchMatrix.scale(e.scaleX, e.scaleY);
                    pinchMatrix.translate(pinchPoint.x/2 , pinchPoint.y/2);
                    this.transform.matrix = pinchMatrix;
    }
    

    is there a better way to do this? I find that this method is very nervous and I lose the picture often. Does anyone have a beautifully clean and smooth to scale a Sprite using pinch without losing the image off-screen. This method is inside a .as class that extends the Sprite class, there is also a similar method for the movement of rotation in this class. Thank you!!!

    Keep a private in your class as attribute:

    private var delay_response_id: int = 0;

    Depending on your event, which received the pinch:

    If (this.delay_response_id > 0) clearTimeout() don't (this.delay_response_id);

    also hides the data needed for the late response

    This.delay_response_id = setTimeout (MyDelay, 500); 0.5 second delay.  Change as needed

    Then in your delayed function:

    private void MyDelay(): void

    {

    This.delay_response_id = 0; reset

    process cached information

    clear the cached information

    }

    Hope that helps.

  • Debugging in Curve 8520 (v4.6.1.272)

    Hello

    I'm trying to debug my App in real aircraft. Don't miss me some steps I think. I followed the steps:

    Advanced (1). the app using BB JDE 4.2.1.

    (2) I have BB Curve BB 8520 i.e with v4.6.1.272 (Platform 4.2.0118)

    (3) downloaded the simulator of RIM BlackBerry_Simulators_4.6.1.272_8520 and installed

    Build (4.) and signed the app.

    (5) the application using javaloader.exe charge

    Attachment (6). the device i.e. Debug > attach to > Handheld > USB (myPIN)

    It gives following o/p on the console:

    Double net.rim.device.apps.internal.clock.face.analog.AnalogClockFace class.
    Found in the net_rim_bb_clock_faces-6 C:\ABS10\Components\JavaDevice\Apps\4.6.1-GeminiGC2\JavaApplications\net\rim\device\apps\internal\clock\face\analog\AnalogClockFace.java.
    Ignored in C:\ABS10\Components\JavaDevice\Apps\4.6.1-GeminiGC2\JavaApplications\net\rim\device\apps\internal\clock\face\analog\AnalogClockFace.java net_rim_bb_clock_lib.
    Double net.rim.device.apps.internal.clock.face.analog.AnalogClockHand class.
    Found in the net_rim_bb_clock_faces-6 C:\ABS10\Components\JavaDevice\Apps\4.6.1-GeminiGC2\JavaApplications\net\rim\device\apps\internal\clock\face\analog\AnalogClockFace.java.
    Ignored in C:\ABS10\Components\JavaDevice\Apps\4.6.1-GeminiGC2\JavaApplications\net\rim\device\apps\internal\clock\face\analog\AnalogClockFace.java net_rim_bb_clock_lib.
    Double net.rim.device.apps.internal.resource.ClockResource class.
    Found in the net_rim_bb_clock_faces-6 C:\tmp\1\rapc_rc_55031.dir\.staging\net\rim\device\apps\internal\resource\ClockResource.java.

    .

    .

    .

    .

    and last lins are:

    VM:-DA 0
    focus: success
    JVM: bklt [1] @9782046: JBSC on = 0
    JVM: bklt [1] @9782046: SC 0
    JVM: bklt [1]: setTimeout 30
    Charger: connect
    Charger: handshake

    After that, my laptop is idle, I dn know not what to do next...? Any suggestion would be appreciated.

    Simon Merci for your quick response. In fact, I forgot to sign the application. And that was the real problem, after having signed it and repeat the above steps, I am able to debug with the device.

  • problem with transparent views

    my application currently charges multiple instances of a class (pageView) off the screen as well as triggered once it can simulate pages. the page mode is basically a such as the sprite class which extends and composed of containers with labels and images.  im having the problem is that when I tween a new page over the last page is transparent and you can see the last page through a new. I tried to create a rectangle and fill it with a white background, but that failed because it covered everything on the screen.  also tried to adjust the alpha of my main container to 1 and also did not work. can someone help me understand this.

    Thank you

    NR

    If the page extends sprite, there a graphical object, it allows to create a strong bg.

    Inside of the manufacturer pageView, or setSize() method:

    this.graphics.beginFill (0 x 0, 1);

    this.graphics.drawRect (0, 0, viewWidth, viewHeight);

    this.graphics.endFill ();

    Where viewWidth and viewHeight are the desired size of your page.

  • Using navigationMovement() as a trackpad/trackball mouse

    Greettings and regards other developers.  a few quick details I use the blackberry JDE 5.0 on Eclipse Galileo, I created a method of mouse for pavers and balls.  Try to expand my horizons of sale, two possible losses haunt my thoughts.

    side 1: the mouse works fine until you roll two directions at once, example left and upwards at the same time moves alone, he left or up not both.

    side 2: the touchpad does not roll like the balloon, this method will probably fine work for the ball, but not the key.

    This is the code for my navigationMovement() method

    protected boolean navigationMovement(int dx,int dy,int status,int time)
        {
            super.navigationMovement(dx, dy, status, time);
            if (!mouseOn)                               //places mouse on first run but doesnt repeat
                {
                mouses.addElement(new Sprite(Utility.SCREEN_WIDTH / 2, Utility.SCREEN_HEIGHT / 2));
                mouseOn = true;
                }
            Sprite f = (Sprite) mouses.firstElement();           //sprite class updates x and y coordinates                                                                               //Focussing on the x/y of the mouse(i know using a vector is silly here)
            f.x+= (dx * 10);
            f.y+= (dy * 10);    //moves the mouse according to dx/dy input
    
            if((f.x + mouse.getWidth()) > Utility.SCREEN_WIDTH) f.x = Utility.SCREEN_WIDTH - mouse.getWidth();
            else if(f.x < 0) f.x = 0;
            if((f.y + mouse.getHeight()) > Utility.SCREEN_HEIGHT) f.y = Utility.SCREEN_HEIGHT - mouse.getHeight();
            else if(f.y < 0) f.y = 0;        //keeps the mouse from scrolling off screen
    
            invalidate();     //update screen
            return true;
        }
    

    Is there a way to make the trackpad act as the trackball with this method, or it will be slow and jerky?  I know that the trackpads have magnitude and direction.  So I hope that's not too bad, it seems to work on the Simulator, but I need a tester phone or real app ready to try this for me.

    More importantly, how do I get the mouse to move both directions if the ball goes both directions? I have some ideas on what may be an if statement to check if both directions are going at once, then run both directions.  But it seems that both must be running.

    Thanks in advance.

    -Andy

    I just realized this post was a little out of place, thanks to blackberry api I got including this one.

Maybe you are looking for

  • Why move them to the bottom of empty in VMware Lab Manager when you use Firefox 4 +?

    When using Mozilla Firefox 4.0 or later, drop boxes in VMware Lab Manager are populated is more if it is not possible to deploy new virtual machines.

  • Satellite P100 - 277 Linux LiveCD Boot from SD card?

    Hey there, my first ever post on these forums, and I had a question. It is possible to unwrap a Linux live CD (like Ubuntu or Mandriva) on a 1 GB SD card (inserted in the multimedia card reader integrated course ;)) and from it? I tried the boot opti

  • LabVIEW application and tablet PC with touch screen

    I was wondering if someone could help me out here... I'm a bit confused. If I wanted to develop an application in Labview (8.5) to a tablet pc that has a touchscreen either (1) Windows 7 Pro, (2) Windows Vista business edition or (3) Windows Xp Table

  • How to measure voltage every minute

    Hi all Currently, I'm new to labview and I'm taking steps of timed voltage.  Here's what I'm trying to do; I'm using labview 2010 and I am currently taking readings of temperature and moisture in sync with each other.  To measure the temperature, I'm

  • Notice of Application install AVG

    I got a flashing notice that says "Application of install AVG" but am afraid to click on it, thinking that it is a link of stuffing to infect me.  But no matter how many times I restart or shut down, he has finally returned.  It is Orange color flash