Jump to content
Search Community

Actual AS3 question - BlitMask

vossiewulf test
Moderator Tag

Recommended Posts

Fact that AS3 is going way of the dodo isn't relevant here, this is a personal project. 

 

Trying to use BlitMask and I must be doing something obviously wrong but not sure what, this is a simple stationary rectangle masking a much larger sprite. ScrollRect works fine, BlitMask doesn't although I get no errors.

 

This is a minimap implementation, sits top right over the main map. I build a 20% scale version of the main map (all I've done so far is the ocean background, however) and then mask. 

public function getMiniMapContent(currMiniMap:LOB_MinimapShiplist_Frame, activeSide:int, scenarioData:Object, useOcean:Boolean) {
	
	//testing	
	useOcean = true;
			
	var miniMapOceanBackground:Sprite = new Sprite();
	miniMapOceanBackground.x = -424;
	miniMapOceanBackground.y = 15;
			
	//Ocean background. Match scenario ocean
	if (useOcean) {
				
		var miniMapOceanSource:LOB_Minimap_Oceans = new LOB_Minimap_Oceans();
		miniMapOceanSource.gotoAndStop(scenarioData.oceanString);

		var oceanBitMapData:BitmapData = new BitmapData(miniMapOceanSource.width, miniMapOceanSource.height);
		oceanBitMapData.draw(miniMapOceanSource);
				
		//calculate map width and height from number of columns/rows specified in scenario file
		var mapWidth:int = Math.ceil(scenarioData.mapNumColumns * MAP_COLUMN_WIDTH * .20);
		var mapHeight:int = Math.ceil(((scenarioData.mapNumRows * MAP_ROW_HEIGHT) + MAP_ROW_INCREMENT) * .20);
				
		miniMapOceanBackground.graphics.beginBitmapFill(oceanBitMapData);
		miniMapOceanBackground.graphics.drawRect(0, 0, mapWidth, mapHeight);
		miniMapOceanBackground.graphics.endFill();
		miniMapOceanBackground.buttonMode = false;
	}
			
	else {
				
		miniMapOceanBackground.graphics.beginFill(0x333333, 1);
		miniMapOceanBackground.graphics.drawRect(-1, -1, 417, 228)
		miniMapOceanBackground.graphics.endFill();
		miniMapOceanBackground.alpha = .33;
	}
			
	currMiniMap.addChild(miniMapOceanBackground);
			
	//miniMapOceanBackground.cacheAsBitmap = true;
	//miniMapOceanBackground.scrollRect = new Rectangle(0,0,417,228);

	var miniMapBlitMask:BlitMask = new BlitMask(miniMapOceanBackground, 0, 0, 417, 228);
	//miniMapBlitMask.autoUpdate = true;
	//miniMapBlitMask.bitmapMode = true;
}

Screenshots, as you see when I toggle on the blitmask the minimap ocean background disappears. Again no errors, so it thinks it's doing the right thing, and I'm probably not telling it the right thing.

 

dl1w0f0.jpg

 

48adIkd.jpg

Link to comment
Share on other sites

Hi and welcome to the forums,

 

Its hard to tell from just looking at your code what may be wrong. 

Does BlitMask work if useOcean is false?

 

 

Since Flash has "gone the way of the dodo bird" we have sunset our AS3 and AS2 projects and support is very limited.

If you can create a reduced test case (not your full project) to clearly illustrate the problem in a Flash FLA that we can easily compile it would help us help you.

You can attach a zip of your FLA file here. I have Flash CS6 and Animate CC available to test with. 

Link to comment
Share on other sites

Good idea about turning the ocean off, I did and I get the same result. Still tells us something, that the blitMask is clearly present and active, but it seems to be masking the target everywhere we can see. My first guess then is it's simply not where I want it to be. Is there any way you can think of for it to show where it thinks it is, like turning the mask opaque?

 

I'll see what I can do to create a test version. Probably a reasonable chance I will figure out the problem in that process, I just thought I might be doing something obviously wrong that you would see.

 

Going back to position, I think the area we want to see might be off the map to the right. The minmap outer frame movieclip is offset by its width to the left so it's registering top right corner to make it easier to handle screen resizing. Starting at 0,0 works for scrollRect, it still seems to register from current top left on the MC. Maybe blitMask is different? I'll try that too.

Link to comment
Share on other sites

...and yep, that's it - it was off screen to the right. If I give the blitMask call a negative starting x I can see it. Oddly though is that it looks offset vertically too, even though when I made the minimap frame register top right I didn't move it vertically, it's still at y = 0.

 

Anyway, now that I can see it I can position it correctly. And I have to toss all the scrollRect code I got working last night to correctly scroll the minimap when mousing over map edge areas. It works, but doesn't look very good, very jerky, so no real loss. Flash mouseover is weird too, if I leave the mouse over a listening object I get three mouseover events and then nothing. Always. Makes continuous scrolling tricky.

 

Thanks for the idea of turning the ocean off, that got me here. I understand about the support, that's why I first said I know it's gone, a personal project in a dying language doesn't require the instant support of someone working under a deadline.

Link to comment
Share on other sites

Explained a bit wrong above, the minimap frame is offset left but of course so is the ocean sprite, and that's the target.

 

scrollRect's starting x and y values are registered from top left of the target sprite's current position - you can set whatever x/y values for the target you want, your mask will start from the target's current top left point. BlitMask, on the other hand, apparently registers from the origin point of the parent sprite and therefore needs to be offset if the target sprite has been offset.

miniMapOceanBackground.scrollRect = new Rectangle(0,0,417,228); 

var miniMapBlitMask:BlitMask = new BlitMask(miniMapOceanBackground, -425, 15, 417, 228); //offset x by -8 and y by 15, it's reading from the parent sprite

//both positioned identically on screen
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...