Reputation: 53
Hopefully this is a simple straightforward one where I'm missing something basic.
Trying to move to tiled background so I can expand my game map without using stupid huge bitmap backgrounds.
I have a symbol/class with a series of tileable bitmaps on a series of labeled keyframes that I'll eventually choose between for each game, right now just trying to get this working and it's hardcoded to the first keyframe frameLabel. This is the code in question, seems to exactly follow advice on how to do this from other sources I looked up before trying this (including the api docs):
var oceanSource:LOB_Ocean_Bkgs = new LOB_Ocean_Bkgs();
oceanSource.gotoAndStop("Atlantic");
var oceanBitMapData:BitmapData = new BitmapData(oceanSource.width, oceanSource.height);
oceanBitMapData.draw(oceanSource);
var oceanBackground:Sprite = new Sprite();
oceanBackground.graphics.beginBitmapFill(oceanBitMapData);
oceanBackground.graphics.drawRect(0, 0, stage.width, stage.height);
oceanBackground.graphics.endFill();
addChild(oceanBackground);
Here's a half-size version of the "Atlantic" keyframe bitmap:
As you see, nothing special, not even the intended final bitmaps, just want to get the structure and the scenario-driven background selection process working before I go to making the final bitmaps.
And half-size version of what see when I render. Please note I have NO errors, I just am not seeing what I expect to see:
When I should be something like this, here it is with the monolithic bitmap background (full size clicky):
============================ UPDATE ON ANSWER ===========================
Answer provided below by www0z0k. Thanks!
I've changed it now to fixed values large enough for all play as intended.
var oceanSource:LOB_Ocean_Bkgs = new LOB_Ocean_Bkgs();
oceanSource.gotoAndStop("Pacific");
var oceanBitMapData:BitmapData = new BitmapData(oceanSource.width, oceanSource.height);
oceanBitMapData.draw(oceanSource);
//oceanBackground is public var declared with class
oceanBackground.graphics.beginBitmapFill(oceanBitMapData);
oceanBackground.graphics.drawRect(0, 0, 6400, 4000);
oceanBackground.graphics.endFill();
//deselect ships listener
oceanBackground.addEventListener(MouseEvent.CLICK, clearShips);
addChildAt(oceanBackground, 0);
Now just need to make it driven by the scenario files and also get my hex grid back; second part of this is separating the hex grid from the background so its color can also be controlled by scenario or by the player.
And also render out some better-looking tileable ocean bitmaps.
Upvotes: 2
Views: 51
Reputation: 4434
Seems like the problem is here:
oceanBackground.graphics.drawRect(0, 0, stage.width, stage.height);
should be
oceanBackground.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
because width
and height
are calculated based on content size while stageWidth
and stageHeight
return actual swf stage size
(see example here)
Upvotes: 4