StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
285 stars 88 forks source link

beginTextureFill() from TextureAtlas bug #86

Closed illuzor closed 8 years ago

illuzor commented 10 years ago

Hello. There is a problem. In case of use beginTextureFill() from atlas, drawed full atlas instead of requested atlas region. My code: sample https://gist.github.com/illuzor/8239923 Project: https://drive.google.com/file/d/0BwbFh6c6Gr70b1lJWEhFWjhNSms/edit?usp=sharing Result screenshot. graphics_bug

IonSwitz commented 10 years ago

This is a bit tricky, but the problem can be solved. The solution lies in the second parameter of the beginTextureFill command, the uvMatrix parameter. Here you can adjust how the texture should be applied to the fill.

Replacing your code in the sample to do this seems to solve the problem ( after addChild(testShape) in your code ):

        var texture:SubTexture = atlas.getTexture("menuBackground") as SubTexture;
        var clipping:Rectangle = texture.clipping;
        var uvMatrix:Matrix = new Matrix();
        uvMatrix.scale(stage.stageWidth / (texture.width * clipping.width), stage.stageHeight / (texture.height * clipping.height));

        testShape.graphics.beginTextureFill(texture, uvMatrix);

        testShape.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);

It might not be the best way to do it, but to me it works fine.

illuzor commented 10 years ago

Thank you for answer. But this solution not works. It`s just stretches image to screen size: streich

IonSwitz commented 10 years ago

Ok, then I don't fully understand what it is you want to achieve with the TextureFill.

What is the desired outcome?

illuzor commented 10 years ago

I want this: needed_result

And I have this result when using single image without atlas: single_image Code: https://gist.github.com/illuzor/8271063

I just want the same result with using TextureAtlas. Is it posible?

IonSwitz commented 10 years ago

Oh, ok, I see. You want the image tiled like that. I'm sorry for misunderstanding you initially.

The problem with tiling an image from an atlas is tricky, and I don't think there is any full, ready-made support in the Starling Graphics Extension for this, nor in any other Starling class, to my knowledge.

I think that it might be better to ask in the general Starling forum:

http://forum.starling-framework.org/

I HOPE I am wrong, and that there is a way to support this, but I don't think there exists a trivial solution.

illuzor commented 10 years ago

Ok. Got it. It would be easier and faster to create my own tool for tiling. Thank you for answers.