Closed mikhailkuts closed 9 years ago
How large is the texture? Remember that the texture doesn't automatically scale with the Rect, so if you want the texture to fill the entire Rect, you need to make the Rectangle as large as the texture, or enter the tricky realm of the uvMatrix (second argument to beginTextureFill),
This code draws a working textureFill for me, with the latest Starling code from GitHub
package
{
import starling.events.Event;
import starling.display.Sprite3D;
import starling.display.Shape;
import starling.textures.Texture;
public class Sprite3DTest extends Sprite3D
{
[Embed( source = "startupbenchmark/starling_bird.png" )]
protected var StarlingBird :Class;
public function Sprite3DTest()
{
super();
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}
protected function onAdded ( e:Event ):void
{
var texture:Texture = Texture.fromBitmap(new StarlingBird);
var shape:Shape = new Shape();
addChild(shape);
shape.x = 400;
shape.graphics.beginTextureFill(texture);
shape.graphics.drawRect(100, 100, 300, 300);
shape.graphics.endFill();
}
}
}
For me your example works too. But when I trying get texture with another way - I didn't see anything.
private function test():void
{
var texture:Texture = getRectTexture(300, 300, 0xFF00FF);
var shape:Shape = new Shape();
view.addChild(shape);
shape.graphics.beginTextureFill(texture);
shape.graphics.drawRect(0, 0, 300, 300);
shape.graphics.endFill();
}
public static function getRectTexture(w:uint, h:uint, c:uint = 0xFF00FF, a:Number = 1):Texture
{
var sp:Sprite = new Sprite();
sp.graphics.beginFill(c, a);
sp.graphics.drawRect(0, 0, w, h);
sp.graphics.endFill();
var bd:BitmapData = new BitmapData(w, h, true, 0x00000000);
bd.draw(sp);
return Texture.fromBitmapData(bd, false, false);
}
If I trying use this texture with image - works fine:
var img:Image = new Image(texture); view.addChild(img);
Seems like I solved a problem. The reason was a generateMipMaps == false. Thanks you! Have no idea why its work on old starling
Hi, I migrated on Starling 1.5.1 (last github sources) and texture filling not working.
var shape:Shape = new Shape(); shape.graphics.beginTextureFill(tx); shape.graphics.drawRect(20, 20, 50, 50); shape.graphics.endFill();
Just a blank screen. Texture is exists with no alpha.