Sprite rendering

First off, I don't understand how rendering works with
an image that is partially visible on screen. Let's say
for example, I have a sprite that is half off screen,
in my rendering method, when I say g2D.drawImage(sprite.getImage(), sprite.getX(), sprite.getY(), observer); What exactly happens? Is time wasted trying to
draw the pixels that are not on the screen? Please ask
me to specify if any other information is needed. Thanks
in advance.
Here are the specs that may be useful:
- uses BuffereStrategy (3 buffers)
- undecorated 'Frame' at fullscreen exclusive mode (640 by 480)

I've often wondered this.
While testing a game I'm working on at the moment I was drawing about 10000 drawRect()'s to the screen per game loop, obviously this slowed the game down, but, when the drawRect()'s weren't onscreen (once I scrolled passed them) the game speed shot back up, so I'm guessing if it isn't drawing drawRect()'s that aren't visible maybe the same applies to images, although I'd further guess that the whole image has to be off screen before its not being drawn, unless java is doing something super cool with the raster (is that right?) that is.
Further, clarification on this from someone who isn't guessing would be nice :)

Similar Messages

  • Strange bug/artefacts on Sprites rendering

    Hi everyone,
    I am experiencing some very strange rendering artefacts on the facebook game I am working on (Mutants: Genetic Gladiators).
    I render our characters as a series of quads drawn with the Graphics class on a bunch of Sprites (no stage 3D here)  that are animated by code. Each Sprite can have its own blending mode and color transform.
    In some situations I can see some bright colored lines along what appears to be the borders of my quads although the image I use as my texture atlas is fully transparent in those areas.
    I observed that the symptoms appear most often when I have quite a lot of overdraw. Especially with mixed blend modes. As an example The particles in the image below are rendered with the "add" blend mode. We can clearly see some unwanted purple outlines.
    The issue is not systematic, it occurs randomly with the same setup but when it does it is repeatable. It has been reported with various versions of the flash player including 11.8.800 and in different browsers (Chome, Firefox, Safari).
    Another interesting aspect is that artefacts don't appear if I hide the background (which is a large bitmapFilled quad with a colortransform).
    Here is another example during his attack, we can clearly see some bounding rectangles of my crabman, especially around the claw. I added a close-up on the artefact and a screen grab of the atlas I use.
    EDIT: As a complimentary information, the artefacts don't appear if I remove the ColorTransforms that I apply on the characters and the background.
    EDIT 2 : The artefacts don't appear in LOW stage quality (which is insufficient for my purposes). The higher the anti-aliasing, the more present the artefacts are.
    Have you experienced similar artefacts? Is there a workaround? Am I doing something evil that breaks the Flash renderer?
    Any help would be greatly appreciated.
    Thanks,
    Phil

    Hi Phil,
    We'd be happy to take a look, but we'll need to run it under a C++ debugger to really understand what's going on.  If possible, it would be great if you could strip this down to a super simple example.  It will make it much faster for us to debug.
    Please file a bug here:
    http://bugbase.adobe.com/
    If you're not comfortable posting examples or details in the public bug, send me a private message and I can pass the information along in our private channels.
    Thanks,
    Jeromie

  • PDF/PrintJob issue - difference b/w Classic and TLF/FTE

    Hi - I'm hoping some Adobe insiders can share some insight on this.
    I'm basically trying to take the final output (page Sprite) rendered from TLF or the Flash Text Engine, and convert it to PDF with selectable vector text.
    I get decent results from using PrintJob and a pdf driver like pdfcreator or cutepdf (both use ghostscript on my machine). However, the text in the pdf isn't selectable.
    This is different when using "classic" Flash9 textfield components.... any text that gets converted is usually selectable. The PDF properties also show (for textfield) that the appropriate font was embedded. Not the case for Tlf TextLines.
    I'm wondering:
    - Is this a bug? Or an interntional design choice (if so, what's the reasoning?)
    - How can I get a PDF made that uses vector fonts and selectable text from FTE output (Sprites)? Ideally I'd want the pdf conversion without the need to use a print driver... so is there any other solution other than printjob - an external library or some server-based loop that can get this done? I want to make the sprites first (and not e.g. directly use PDF's API) because of the layout requirements... Flash FTE / TLF works great for that for us.
    Any help on this would be super! So thanks in advnace,

    Hi Robin,
    Thanks so much for the response.
    That indeed sounds like precisely the issue.
    Is there no way to add that extra info about selectability to TextLine (or
    is there some reference of which properties or fields are maintained by
    TextField for this info and that could be used to make an extended TextLine
    object with those extra bits?
    Or what about trying to replace all TextLines with TextFields just before
    printing (by reading their rawtext etc) - the part of that I'm uncertain of
    is would textfields render the text precisely as textlines do... somehow I
    doubt the kerning / tracking would be the same... certainly things like
    vertical text etc wouldn't be possiible.
    The link you shared is very promising - unfortunately the gentleman hasn't
    shared how he did that so there's no way to tell what his approach is. With
    a little digging it seems they make the PDF by sending the TLF textflow xml
    to a server... its possible he's using something like Weborb server (
    http://themidnightcoders.com/) and have a template made for the TLF xml.
    Unfortunately that sounds like too specific a solution, we wouldn't be able
    to take advantage of how we meet our layout spec using FTE.
    Sorry for the convoluted response - I thought I'd share more food for
    thought.

  • Frame skip/choppy frame rate problems

    Hi all,
    I have been benchmarking different sprite rendering methods on iPhone, and seem to have a consistently choppy framerate when publishing using CPU.  If I use GPU the frame rate is not choppy, but the overall performance is much slower.
    I have a detailed analysis here: http://www.pixelthismobile.com/blog/1/10/2010/flash-iphone-wildly-fluctuating-framerate-or -frame-skip
    All I am doing is drawing a number of sprites to a static bitmap on the stage (using copyPixels), clearing the bitmap before each frame.
    Basically the framerate jumps rapidly between two values (a low and a high - for example 15 fps and 52 fps) at a very consistent rate of about 3 cycles per second.  I am at a loss...
    Would be great if anybody had any insights.
    Regards,
    Peter
    p.s. This uses PFI v1, have yet to try with v2.

    I'm starting to get to the bottom of this! Seems the choppy performance is being caused by my benchmarking routine, which pushes a single Number value on to an array every frame.   I assumed this was due to memory allocation so I tried a fixed size array and simply setting a value each frame. Still choppy.  So I got rid of the benchmark code altogether. All that is left is this code: frameCount++; And the choppy frame problem is STILL there! Without the ++ it is fine o.O - how absolutely bizarre. Who would have thought a post increment would cause a choppy frame rate!?  Still doing more testing so stay tuned...
    Nope - it is frame skip

  • How to use filters on ios mobile devices (iPhone/iPad) using GPU rendering (Solved)

    Many moons ago I asked a question here on the forums about how to use filters (specifically a glow filter) on a mobile devices (specifically the iPhone) when using GPU rendering and high resolution.
    At the time, there was no answer... filters were unsupported. Period.
    Well, Thanks to a buddy of mine, this problem has been solved and I can report that I have gotten a color matrix filter for desaturation AND a glow filter working on the iPhone and the iPad using GPU rendering and high resolution.
    The solution, in a nut shell is as follows:
    1: Create your display object... ie: a sprite.
    2. Apply your filter to the sprite like you normally would.
    3. Create a new bitmapdata and then draw that display object into the bitmap data.
    4. Put the new bitmapdata into a bitmap and then put it on the stage or do what you want.
    When you draw the display object into the bitmapdata, it will draw it WITH THE FILTER!
    So even if you put your display object onto the stage, the filter will not be visible, but the new bitmapdata will!
    Here is a sample app I created and tested on the iphone and ipad
    var bm:Bitmap;
    // temp bitmap object
    var bmData:BitmapData;
    // temp bitmapData object
    var m:Matrix;
    // temp matrix object
    var gl:GlowFilter;
    // the glow filter we are going to use
    var sprGL:Sprite;
    // the source sprite we are going to apply the filter too
    var sprGL2:Sprite;
    // the sprite that will hold our final bitmapdata containing the original sprite with a filter.
    // create the filters we are going to use.
    gl = new GlowFilter(0xFF0000, 0.9, 10, 10, 5, 2, false, false);
    // create the source sprite that will use our glow filter.
    sprGL = new Sprite();
    // create a bitmap with any image from our library to place into our source sprite.
    bm = new Bitmap(new Msgbox_Background(), "auto", true);
    // add the bitmap to our source sprite.
    sprGL.addChild(bm);
    // add the glow filter to the source sprite.
    sprGL.filters = [gl];
    // create the bitmapdata that will draw our glowing sprite.
    sprGL2 = new Sprite();
    // create the bitmap data to hold our new image... remember, with glow filters, you need to add the padding for the flow manually. Should be double the blur size
    bmData = new BitmapData(sprGL.width+20, sprGL.height+20, true, 0);
    // create a matrix to translate our source image when we draw it. Should be the same as our filter blur size.
    m = new Matrix(1,0,0,1, 10, 10);
    // draw the source sprite containing the filter into our bitmap data
    bmData.draw(sprGL, m);
    // put the new bitmap data into a bitmap so we can see it on screen.
    bm = new Bitmap(bmData, "auto", true);
    // put the new bitmap into a sprite - this is just because the rest of my test app needed it, you can probably just put the bitmap right on the screen directly.
    sprGL2.addChild(bm);
    // put the source sprite with the filter on the stage. It should draw, but you will not see the filter.
    sprGL.x = 100;
    sprGL.y = 50;
    this.addChild(sprGL);
    // put the filtered sprite on the stage. it shoudl appear like the source sprite, but a little bigger (because of the glow padding)
    // and unlike the source sprite, the flow filter should acutally be visible now!
    sprGL2.x = 300;
    sprGL2.y = 50;
    this.addChild(sprGL2);

    Great stuff dave
    I currently have a slider which changes the hue of an image in a movieclip, I need it to move through he full range -180 to 180.
    I desperately need to get this working on a tablet but cant get the filters to work in GPU mode. My application works too slow in cpu mode.
    var Mcolor:AdjustColor = new AdjustColor();   //This object will hold the color properties
    var Mfilter:ColorMatrixFilter;                           //Will store the modified color filter to change the image
    var markerSli:SliderUI = new SliderUI(stage, "x", markerSli.track_mc, markerSli.slider_mc, -180, 180, 0, 1);   //using slider from http://evolve.reintroducing.com
    Mcolor.brightness = 0;  Mcolor.contrast = 0; Mcolor.hue = 0; Mcolor.saturation = 0;            // Set initial value for filter
    markerSli.addEventListener(SliderUIEvent.ON_UPDATE, markerSlider);                          // listen for slider changes
    function markerSlider($evt:SliderUIEvent):void {
        Mcolor.hue = $evt.currentValue;                        
        updateM();
    function updateM():void{
        Mfilter = new ColorMatrixFilter(Mcolor.CalculateFinalFlatArray());
        all.marker.filters = [Mfilter];
    how would I use your solution in my case
    many thanks.

  • Rendering diagnostics not working in AIR 2.6

    I'm trying to move my pfi application over to AIR 2.6 and am experiencing a huge drop in frame rate.  I worked quite hard to make sure everything was cached with the GPU when working with pfi and found the rendering diagnostics to be invaluable in helping me nail down areas where the graphics weren't being cached properly.  I thought I would check to make sure that the graphics are still being cached in AIR 2.6 but when I built the application with the flag enabled, the rendering diagnostics didn't turn on.  The flag is CTTextureUploadTracking and is part of the application xml:
    <InfoAdditions>
    <![CDATA[
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleBlackOpaque</string>
    <key>UIRequiresPersistentWiFi</key>
    <string>NO</string>
    <key>UIDeviceFamily</key>
    <array>
    <string>1</string>
    <string>2</string>
    </array>
    <key>CTTextureUploadTracking</key>
    <true/>
    ]]>
    </InfoAdditions>
    I also tried adding the -renderingdiagnostics flag to the command line as indicated in http://download.macromedia.com/pub/labs/packagerforiphone/packagerforiphone_devguide.pdf but I get an error telling me that "The -renderingdiagnostics flag is no longer supported".  Does anyone know how to enable this now?

    If Adobe ever wants developers to properly utilize the GPU then a tool like rendering diagnostics needs to exist.  Flash has a terrible stigma of being a processor hog, slow and glitchy.  Flash doesn't need to be like this but lots and lots of sloppy coding have helped this become what people perceive as reality.  Even if 2.7 is leaps and bounds above 2.6, if no one can properly figure out how to keep data cached with the gpu then Flash apps will still be slow, battery hogs.  A visual troubleshooting tool for gpu caching problems is really essential.  If it hadn't been for that I would never have been able to figure out some of the bizarre quirks in caching.  For instance, if you have an opaque background in a Sprite and you add something to it as a child, the gpu will never be able to cache either of them correctly.  Why? I don't know, it doesn't make sense but the rendering diagnostics helped me find the problem quickly.  Please add this tool or something like it back in.  You're doing your devs a serious disservice and, consequently, helping push the idea that Flash is a technology that is no longer relevant.

  • XML dataset stucks in rendering on html page

    Hi
    When i choose a test.xml file with 'insert - spry dataset', 'datatype xml', the datapreview in the 'set data options' window display the data correctly.
    In the 'choose insert options' i choose 'insert table'. I don't use the setup button there, leaving it to default settings, and click 'done'.
    Seems to be correct.
    In the design window, the columnheaders are displayed, with the fields name between brackets, like below:
    Datum     Inhoud     Link
    {datum}     {inhoud}     {link}
    the values are not visible in designview.
    But in liveview, the page is completely blank.
    I'm not hosting it yet on a testsite. Just trying out how to insert XML data in a HTML file.
    According to the tutotials it should work - but it doesn't...
    the pieces of code in the html that were automatically added:
        <script src="file:///C|/Users/Frank Buurman/AppData/Roaming/Adobe/Dreamweaver CS4/en_US/Configuration/Temp/Assets/eamA7B0.tmp/xpath.js" type="text/javascript"></script>
            <script src="file:///C|/Users/Frank Buurman/AppData/Roaming/Adobe/Dreamweaver CS4/en_US/Configuration/Temp/Assets/eamA7B0.tmp/SpryData.js" type="text/javascript"></script>
                      </p>
                            <div spry:region="ds1">
                              <table>
                                <tr>
                                  <th spry:sort="datum">Datum</th>
                                  <th spry:sort="inhoud">Inhoud</th>
                                  <th spry:sort="link">Link</th>
                                </tr>
                                <tr spry:repeat="ds1">
                                  <td>{datum}</td>
                                  <td>{inhoud}</td>
                                  <td>{link}</td>
                                </tr>
                              </table>
                      </div>
                            <p> </p>
                    </div>
    Could you please help me out ?
    tnx a lot !

    I have no testing server yet.
    The hourglas is in Dreamweaver itself, when rendering the xml sprite - not in a browser.
    Attached is a testing html (with associated css and js files)  in wich i tried to insert the xml.
    When i tried the same on a blank html page (in the same dir), the spry table insertion works fine .
    But not within the contentarea of this index.html.
    Could it be because of the 'accordion.js' ?
    Or the css ?
    I really have no idea...
    tnx
    (ps i've left out the images folder)

  • Which one is better to manage sprites??

    hello,
    i have a class that manage all my sprites, from updating to rendering
    and because there will be many sprites iterated every game loop
    i want to know which one is faster between these :
    1. i put ALL sprites (active and not active) in the sprite manager and update the sprite based on whenever it's active or not
    OR
    2. i put only active sprite and the sprite that not active is removed from the list, in this case in every loop i must add new active sprite to the list and remove nonactive sprite from the list
    the code will be like this :
    for number 1
    ArrayList spritelist; // list of the sprites
    public void update(Graphics g) {
         for (int i=0;i < spritelist.size();i++) {
              Sprite s = (Sprite) spritelist.get(i);
              if (s.active()) {
                   s.update();
                   s.render(g);
    ......and for number 2
    ArrayList spritelist; // list of the sprites
    public void update(Graphics g) {
         for (int i=0;i < spritelist.size();i++) {
              Sprite s = (Sprite) spritelist.get(i);
              if (s.active()) {
                   s.update();
                   s.render(g);
              } else { spritelist.remove(i); i--; }
    ......in code 1, there will be many sprites to iterate, and in code 2, there will be many adding and removing sprite from the list
    so my question is:
    is iterating on many sprites and get it's active status is faster or
    iterate on few sprites and use ArrayList.add() and ArrayList.remove()
    Thanks in advance........

    Rules about optimizing:
    1)     Dont do it.
    2)     (experts only) Dont do it yet.
    Do you have less than 10000 sprites? Do you add or remove more than 1000 sprites for each iteration in the game loop?
    The answer is likely to be no.
    Is the time it takes to do the painting of one single sprite plus the time it takes to do calculation regarding the movement of one single sprite grater than the time it takes to iterate over an array of 1000 sprites?
    The answer is likely to be yes.
    So, in what part of your code should you twist your head to do some optimizing?
    Not here!
    And where should you concentrate about maintainability?

  • Update cell Sprite in DataGrid

    Hi,
    I have a datagrid with a LOT of sprites (1700 circles, squares, and triangles) that I created in an itemRenderer in Actionscript using Peter Ent's excellent tutorial on custom item renderers. http://www.adobe.com/devnet/flex/articles/itemrenderers_pt5_03.html. Therefore, the Sprites inherit from UIComponent.
    I need to dynamically update a few of these sprites based on new data I pull down from the server once per minute.
    A full-page refresh is to be avoided since it takes 3-4 seconds to load and is disruptive to the user experience.
    Getting the row/column # from the datagrid's itemClick event is dead simple, but I don't see my Sprite when I look at the data using the debugger.
    What is the syntax to retrieve a given cell's Sprite from the application? Also, once I have that Sprite, how do I update/replace a Sprite only in that cell?
    Please help.
    Thanks!!!

    You're right, it isn't adding rows.
    I'm not sure what you mean by 'all the sprites are chosen based on the data  object and that old existing sprites get removed or re-purposed'.
    I have 3 grids, but for the sake of simplicity will focus on just 1.
    There are 39 rows and 15 columns. Each has a Sprite. At the moment, each column has its own custom ItemRenderer since there are data tags unique to each. I've noticed that the whole Object is passed in, so I *could* have one ginormous class to create Sprites for all 15 columns of a row at once, but (1) it didn't work to put that ItemRenderer at the datagrid level versus the individual column level and (2) I'm not sure which is more efficient.
    Anyway, back to the most pressing problem: how to update Sprites in the grid from data updates.
    Here is the code for the custom Item Renderer:
    package utilities
         import flash.display.Sprite;
         import mx.controls.ToolTip;
         import mx.controls.listClasses.IListItemRenderer;
         import mx.core.UIComponent;
         import mx.events.FlexEvent;
         public class Drop1Renderer extends UIComponent implements IListItemRenderer
              public function Drop1Renderer()
                   super();
                   height=20;
                   width=16;
              // Internal variable for property
              private var _data:Object;
              // Make it bindable
              [Bindable("dataChange")]
              // Define the getter
              public function get data():Object
                   return _data;
              //define the setter
              public function set data(value:Object):void
                   _data = value;
                   invalidateProperties();
                   dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
                   if (value.deviceType1 != "Null")
                        var mySprite:Sprite = new Sprite();
                        mySprite.cacheAsBitmap=false;
                        buttonMode=true;
                        var uic:UIComponent = new UIComponent();
                        mySprite.graphics.beginFill(value.deviceColor1);
                        var triangleHeight:Number = 12;
                        switch (value.deviceType1)
                             case "Circle":
                                  mySprite.graphics.lineStyle(1,0x000000, .5);
                                  mySprite.graphics.drawCircle(8, 9, 5);
                                  break;
                             case "CircleBlue":
                                  mySprite.graphics.lineStyle(2,0x0000DD, .9);
                                  mySprite.graphics.drawCircle(8, 9, 5);
                                  break;
                             case "TriangleRed":
                                  mySprite.graphics.lineStyle(2,0xFF0000, .9);
                                  mySprite.graphics.moveTo((triangleHeight/2)+2, 3);
                                  mySprite.graphics.lineTo(triangleHeight+2, triangleHeight+1);
                                  mySprite.graphics.lineTo(2, triangleHeight+1);
                                  mySprite.graphics.lineTo((triangleHeight/2)+2, 3);
                                  break;
                             case "Triangle":
                                  mySprite.graphics.lineStyle(1,0x000000, .5);
                                  mySprite.graphics.moveTo((triangleHeight/2)+2, 3);
                                  mySprite.graphics.lineTo(triangleHeight+2, triangleHeight+1);
                                  mySprite.graphics.lineTo(2, triangleHeight+1);
                                  mySprite.graphics.lineTo((triangleHeight/2)+2, 3);
                                  break;
                             case "TriangleBlue":
                                  mySprite.graphics.lineStyle(2,0x0000DD, .9);
                                  mySprite.graphics.moveTo((triangleHeight/2)+2, 3);
                                  mySprite.graphics.lineTo(triangleHeight+2, triangleHeight+1);
                                  mySprite.graphics.lineTo(2, triangleHeight+1);
                                  mySprite.graphics.lineTo((triangleHeight/2)+2, 3);
                                  break;
                             case "Rect":
                                  mySprite.graphics.lineStyle(1,0x000000, .5);
                                  mySprite.graphics.drawRect(3, 4, 10, 10);
                                  break;
                             case "RectBlue":
                                  mySprite.graphics.lineStyle(2,0x0000DD, .9);
                                  mySprite.graphics.drawRect(3, 4, 10, 10);
                                  break;
                             case "RectOrange":
                                  mySprite.graphics.lineStyle(2,0xFFA500, .9);
                                  mySprite.graphics.drawRect(3, 4, 10, 10);
                                  break;
                             case "Ellipse":
                                  mySprite.graphics.lineStyle(1,0x000000, .7);
                                  mySprite.graphics.drawEllipse(2, 5, 12, 6);
                                  break;
                             default:
                                  mySprite.graphics.drawCircle(8, 9, 5);
                        uic.addChild(mySprite);
                        this.addChild(uic);
                        uic.toolTip = "Howdy there!";
              override protected function createChildren() : void
                   super.createChildren();
              override protected function commitProperties() : void
                   super.commitProperties();
              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                   super.updateDisplayList(unscaledWidth, unscaledHeight);

  • Creating a sprite

    ok here is the deal. I want a flock of birds to fly accross
    my web page. so I went to poser and rendered a bird in flight as 60
    separate frames in ping format so there wouldn't be any background.
    I then imported all the frames into the flash library and created
    60 different layers each one with one of the frames of the bird
    flying. When i play the movie the bird looks pretty good. I do not
    however know how to turn these 60 layers into one flying bird. How
    do i convert the layers into a sprite that I can then duplicate and
    move around? something that can be exported so that I can use it on
    other projects and pages?

    look under help docs for "symbols" - the basic building block
    of Flash - if there's one thing
    everyone learns first in Flash - Symbols is it.
    Open Library and from drop down menu create a new symbol -
    you will want to select and copy frames
    of your image sequence and paste frames into this new symbol
    - now you can drag instances of this
    symbol to the stage multiple times.
    Chris Georgenes / mudbubble.com / keyframer.com / Adobe
    Community Expert
    shadowrelm wrote:
    > ok here is the deal. I want a flock of birds to fly
    accross my web page. so I
    > went to poser and rendered a bird in flight as 60
    separate frames in ping
    > format so there wouldn't be any background. I then
    imported all the frames into
    > the flash library and created 60 different layers each
    one with one of the
    > frames of the bird flying. When i play the movie the
    bird looks pretty good.
    > I do not however know how to turn these 60 layers into
    one flying bird. How do
    > i convert the layers into a sprite that I can then
    duplicate and move around?
    > something that can be exported so that I can use it on
    other projects and pages?
    >

  • As3IsoLib: Loading Image and Adding to Sprite.

    I'm using a library called 'As3IsoLib' in my isometric game to create sprites and other elements. Currently I add a sprite and load an image to be displayed for the sprite. Up until now I have not checked to see when the image has actually loaded as I just straight away add it. That's got me thus far but now I'm expericening 'security' errors in flash which apparently mean it's trying to add an image which hasn't yet fully loaded.
    Since I was going to be loading lots of images I put such under a function entitled 'LoadImg'. This is passed a string that is the location of the image we wish to load.
    var UnitSprite:IsoSprite;
    UnitSprite.moveTo(0, 0, 0);
    UnitSprite.sprites=[LoadImg('imgs/picture.png')];
    DrawSprite(UnitSprite);
    function LoadImg(Img:String):Loader
         var myLoader:Loader;
         myLoader=new Loader();
         myLoader.load(new URLRequest(Img));
         return myLoader;
    But now I need to say when it's completed loading the image then return the loader which isn't possible. I can't add an event handler saying when the 'myLoader' has completed because then you have to supply a second function rendering me unable to use return. I also cannot pass it the sprite I wish to add the image to. I've read in AS2 you were able to pass additional arguments. Such would solve my problem via something along the lines of...
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, AddImg(SpriteToAddImgTo));
    function AddImg(e:Event,Spr:IsoSprite)
        Spr.sprites = [e.target];
    But I'm using AS3 so I cannot do such. I've read several times on the Internet that it is possible to pass addional arguments ( see http://sinfinity.pl/blog/2012/03/28/adding-parameters-to-event-listener-in-flex-air-as3/ )
    but I cannot get it to work. How might I achieve this?

    that may (or may not) be caused by trying to use the loader's content before loading is complete.  to remedy the problem, if it's caused by trying to use the loader's content before loading is complete use:
    var UnitSprite:IsoSprite;
    UnitSprite.moveTo(0, 0, 0);
         var myLoader:Loader;
    LoadImg('imgs/picture.png');
    function LoadImg(Img:String):void
    myLoader=new Loader();
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, AddImg);   
    myLoader.load(new URLRequest(Img));
    function AddImg(e:Event)
    Spr.sprites = [e.target];
    UnitSprite.sprites=Bitmap(myLoader.content); 
    DrawSprite(UnitSprite); }

  • Game rendering and memory optimization in AIR for Android

    I am coding an engine for android that uses the fastest methods so I can rapidly make android and iphone (if possible) games.
    1) using GPU rendering, are the bitmapData functions like copyPixels accelerated?
    in other words is it faster to use only copyPixels to render all my game objects to one bitmap or use separate sprites?
    2) this is a general air question, if I want to clear memory used, like for example when moving to a new stage and I want to delete those bitmaps that been used on the previous stage.
    is there a function to force them to be removed from memory, or should I just remove all the references?
    also if I remove all the references from an object it will be deleted if it's listening for events from another object?
    Thanks.

    1. Various forum posts and articles I've seen suggest a blitting approach like copying bitmaps together gives roughly the same performance results as separate sprites with GPU rendering.
    Might be a good idea to setup a processor intensive game scenario and try each for comparison? I'l be interested in hearing how you get on.
    TBH I haven't tried the copyPixels approach yet, so i'll be playing around with it myself soon.
    2. Yes, removing references is the way to get objects garbage collected. There are ways to force garbage collection, but they are hacky. Definitely not good practice.
    And yes make sure you remove the event listeners because as you suspect, they will keep the objects alive.
    There is an argument called 'use weak reference' which you can set to true when you add the event listener. This is intended to prevent them keeping objects alive, but I have seen situations where it doesn't work properly.

  • Best method for animated bitmap sprites with GPU?

    I've been looking at how GPU Hardware Acceleration is achieved with cacheAsBitmap and cacheAsBitmapMatrix which I understand for static bitmap sprites (+rotation/scale) but I don't quite understand how this would be used to animate a sprite that had different animation frames.. in terms of what is done by the GPU and what is done by the CPU
    eg potential scenarios:
    1) cache sprite sheets to GPU. use copyPixels to blit the various sprites to a single canvas. In this case presumably the canvas would not be GPU accelerated because it is constantly changing every frame. Is there in fact any benefit of having the sprite sheet cached here? is the GPU actually used for the blit onto the CPU-rendered canvas?
    2) cache individual sprite bitmap(data) frames on the GPU. use object pooling for game character sprites and add them to stage on startup. Change the bitmap every frame dynamically,  for animated sprites, to one of the cached bitmapdata textures. is the GPU actually being used in this case to change the bitmap of the sprite? or is it forced to CPU processing again?
    The only scenario I currently know should be GPU accelerated is if I use a cached sprite that doesn't animate (other than rotating and scaling with the bitmap matrix).
    thanks for any advice
    J

    J, I believe (2) is how it is currently done. A better method is required! - basically the same question I have that you are helping me with . That link to 'Yeah, but is it Flash' in my post shows an example of exactly that method (individual BitmapData for each frame).
    Just for completeness I will add the one from my post (though unsure if it is even possible):
    (3) Single BitmapData sprite sheet cached to GPU. Each Bitmap that uses this sprite sheet can somehow specify the x,y,width,height of the frame within this sprite sheet to use.

  • Image rendering

    I don't understand how rendering works with an image
    that is partially visible on screen. Let's say for
    example, I have a sprite that is half off screen. In
    the rendering method, when I say
    g2D.drawImage(sprite.getImage(), sprite.getX(), sprite.getY(), imObsrvr);
    What exactly happens? Is time wasted trying to draw
    the pixels that are not on the screen? Please ask me
    to specify if any other information is needed. Thanks
    in advance.
    Here are the specs that may be useful:
    - uses BuffereStrategy (3 buffers)
    - undecorated 'Frame' at fullscreen exclusive mode (640 x 480)

    don't worry about it, the image drawing is clipped.

  • Can't open popup window in item renderer

    I have a datagrid with two columns. Each column has it's own
    itemRenderer. The itemRenderers have there own class. In one
    itemrenderer I have a link button and it has a click event that is
    associated with it in the script block of that class. Inside the
    click event I have the following code to create a popup:
    var popup_win:MyWindowType = MyWindowType
    (PopUpManager.createPopUp (this, MyWindowType , true));
    When I click the linbutton I will see a flash and a blur
    affect as if the window is trying to open but never does. I've
    traced "this" and it's the renderer... So I tryed to reference back
    up the that class that has the datagrid control... which is
    this.parent.parent.parent... but that doesn't work either. I'm
    basically trying to open a window that allows the user to choose
    some stuff from a radio button and then when they click ok on the
    popup window it does some validation and then the contents get's
    changed in the cell that it came from. I want the popup to open
    upon clicking of the link button or else I would use the editor
    functionality. Any ideas of how I could do this?

    Good Day
    I had the same idea for an itemrenderer....but I'm using the
    mouse_over event.
    A titlewindow pops up when moving over a row in the datagrid,
    and closes when moving out.
    The intent of the popup is to show some charts and additional
    links.
    However, when the popup shows, and I move my mouse into the
    popup box, the mouse movements are still being registered by the
    datagrid row below the popup box...hence making a new popup box
    appear every time I move the mouse.
    I tried to set focus on the popup alone...but still doesn't
    work.
    Here's the itemrenderer code:
    <mx:Text xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="_OnCC()" mouseOut="_mOut()">
    <mx:Script>
    <![CDATA[
    import mx.core.Application;
    import flash.events.MouseEvent;
    import mx.managers.PopUpManager;
    //import mx.controls.Alert;
    private var pop1:_popup_gridb;
    public var currentColumn:String = "";
    public function _OnCC():void{
    var currentXml:XML = new
    XML(data..field.(@columnname==currentColumn));
    text = currentXml.@value;
    text = text.toUpperCase();
    addEventListener(MouseEvent.MOUSE_OVER, _mOver);
    //addEventListener(MouseEvent.MOUSE_OUT, _mOut);
    private function _mOver(event:MouseEvent):void{
    //Alert.show("Hello World");
    pop1 = _popup_gridb(
    PopUpManager.createPopUp(DisplayObject(this.parentApplication),_popup_gridb,false));
    //PopUpManager.createPopUp(Application.application as
    Sprite,_popup_gridb,false));
    //PopUpManager.createPopUp(this,_popup_gridb,false));
    pop1.showCloseButton=true;
    pop1.id = "_pu" + Math.random();
    //pop1.dataView = dv;
    pop1.title = pop1.id.toString();
    PopUpManager.centerPopUp(pop1);
    //removeEventListener(MouseEvent.ROLL_OVER,_mOver);
    private function _mOut():void{
    PopUpManager.removePopUp(pop1);
    //addEventListener(MouseEvent.ROLL_OVER, _mOver);
    ]]>
    </mx:Script>
    </mx:Text>
    Currently, the popup is just a titlewindow w/a datagrid
    inside.
    thx
    j

Maybe you are looking for

  • My iPhone went to Recovery mode, could not able to restore it back to working state

    Iam iPhone4 user, Recently my iPhone  shows only iTunes symbol. When I connect it to iTunes, it is saying "iPhone in Recovery mode". When I Restore the iPhone, I could not be able to do it. When i check the update logs. Found the following error    

  • Report for Shipment cost calculation based on Delviery Line items

    Hi, What would be the Standard SAP report where I can find the shipment cost based on Delivery line item. Currently there is a report ME2S that gives the cost based on PO. But I want to find a report based on outbound delivery line item. Regards Gaur

  • Using normal classes in a JSP

    I have written a library of classes for use in a standard application. In a completely separate project I need to use these classes in a JSP page. Under %tomcat/webapps/myproject is the JSP file. Where do I place the "normal" class files and how do I

  • Problem in creating idocs

    hi, While creating idocs I created logical system using SPRO,then created RFC then Port but when i am creating partner profiles I am unable to get the destination system which I have created.Could any one guide me.

  • Making combo box write variables

    Hi I am a dynamic site newbie, but have been making simple animations with Flash for some years. I have got a friend to give me a leg up to create a flash page full of input text boxes that write to a text file via PHP and are then dispayed in dynami