0
votes

I'm trying to add an image to a sprite then add it to the grid. The original size of the image is 276x202. However when it's been added to the grid it increases in size.

http://i.imgur.com/P1Jlq.png

The result is

http://i.imgur.com/0UPBH.png

public class main extends MovieClip
{

    public function main() 
    {
        var view:IsoView = new IsoView();
        view.setSize((stage.stageWidth), stage.stageHeight);
        view.clipContent = true;
        addChild(view);

        var gridHolder:IsoScene = new IsoScene();
        view.addScene(gridHolder);
        var scene:IsoScene = new IsoScene();
        view.addScene(scene);

        graphics.beginFill(0x000000, 1);
        graphics.drawRect(0, 0, 800, 600);graphics.endFill();

        var grid:IsoGrid = new IsoGrid();
        grid.cellSize = 40;
        grid.setGridSize(20, 20, 0);
        gridHolder.addChild(grid);
        gridHolder.render();

        //var box:IsoBox = new IsoBox();
        //box.setSize(40, 40, 40);
        //box.moveTo(80, 80, 0);
        //scene.addChild(box);

        var player:IsoSprite;
        var myLoader:Loader;

        myLoader=new Loader();
        myLoader.load(new URLRequest('imgs/DesertTankNE.png'));
        //myLoader.width = 5; //Makes image disappear no matter what value is set.
        //myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnComplete); //Doesn't change anything if we say on completion of loading image add it to the sprite.

        player = new IsoSprite();
        player.sprites = [myLoader];

        //player.setSize(1,1,0); //Doesn't seem to affect anything no matter what size specified.
        //player.width = 2; //Same as above

        scene.addChild(player);
        scene.render();

    }

}

I've tried setting the width and height of the image when loading it and also tried setting the size of the sprite. The former makes the image not appear no matter what value is set and the latter doesn't seem to affect anything.

1
I am not familiar with the isoLib framework but to me it looks like you have a scaling issue. If IsoView extends from UIcomponent than calling setSize explicitly like you are will cause issues help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/… - The_asMan

1 Answers

0
votes

There is absolutely nothing wrong with your as3isolib code, and the image is not being resized in any way by code. Compare the tank image to the size of the grid cells (which should be 20 pixels width by 20 pixels height) and you should see that their relative sizes are ok.

The only problem there is that the whole flash stage is being resized. Are you testing your flash movie on the browser perhaps? Make sure you aren't setting the flash movie's width and height as 100% of its container in the HTML. If the flash movie is in a div and flash is told to be a width and height of 100%, it will stretch out to whatever size the div is.

Seeing your code I think you want your stage size to be 800x600; set your flash movie to those dimensions using the metatag SWF, for example:

[SWF(width="800", height="600", frameRate="30", backgroundColor="#FFFFFF")]

If you are using Flash Builder, you might need to clean your project a couple of times (Project -> Clean) to clear the previous compiler settings. Test your SWF movie outside of the broswer (double click the SWF file to open it on your local flash player) and make sure it has the proper dimensions. You should see the tank and the grid cells the right size now.

If you want to test it in the browser, don't use the HTML wrapper generated by Flash Builder (or Flash Pro). Make your own html using swfobject and set the correct width and height, for example:

<script type="text/javascript">
    swfobject.embedSWF("myIsoTank.swf", "flash_container_div", "800", "600", "10", "expressInstall.swf");
</script>

This should get rid of your problem.