I have a screen scaled to twice his size and most of my graphics are 16x16 (tiles and entities) so every entity is 32x32 in screen. what i want to do is that one special entity renders in the screen without scaling to 32x32, just have this entity’s size being 16x16. I have been trying to modify the image’s rendering, but i cant really find where it is scaled.
Scaling everything on the screen but some entitys
If you’re doubling your scale with FP.screen.scale
, your only recourse would be to set your special Entity
's scale to 0.5
.
Image(specialEntity.graphic).scale = 0.5;
This won’t look great, since it’ll essentially be rendering your special Entity
as an 8x8 image, then blowing it up twice the size.
The best solution would be to not scale the FlashPunk screen at all, but scale all your other Entity
graphics to twice their original size. The most optimal way to do this would be to do this to your sprites before importing them into your game; however, you can also scale them in game as well.
thanks for your answer. I dont think that scale the entity will work but i like the other idea, i’ll scale the tile’s bitmap before embeding it in flashdevelop and then set the image graphic to it.
PD: the site looks great
edit: if anyone see this topic and wants to know how to scale the image, i created this simple function for it.
public static function getScaledBitmapData(source:Class, scale:Number):BitmapData
{
var sourceBitmap:Bitmap = new source();
var sourceBitmapdata:BitmapData = sourceBitmap.bitmapData;
var matrix:Matrix = new Matrix();
matrix.scale(scale, scale);
var scaledBitmapdata:BitmapData = new BitmapData(sourceBitmapdata.width * scale, sourceBitmapdata.height * scale, true, 0x000000);
scaledBitmapdata.draw(sourceBitmapdata, matrix);
return scaledBitmapdata;
}
Just put it anywhere, for example in the FP class and use it like this:
var a:Image = new Image(FP.getScaledBitmapData(*reference to the embeded graphic*));
Or any graphic you like.
How would you scale a tilemap with this? I get this error:
Implicit coercion of a value of type net.flashpunk.graphics:Tilemap to an unrelated type Class.
var a:Tilemap= new Tilemap(FP.getScaledBitmapData(*reference to the embeded graphic*), etc...);
Well, the thing is, I have this
private var _map_Ground:Tilemap;
[Embed(source="../../levels/Dungeon_1.png")]private const DUNGEON_1:Class
and a tmx file here
I fill up the tilemap with some code (parsing from the tmx file)
then
var groundlayer:Tilemap= new Tilemap(getScaledBitmapData(_map_Ground), 6);
addGraphic(groundlayer);
but I get these errors:
Implicit coercion of a value of type net.flashpunk.graphics:Tilemap to an unrelated type Class.
Incorrect number of arguments. Expected 5.
var groundlayer:Tilemap = new Tilemap (getScaledBitmapData(_map_Ground, 6));```
I do, that’s what I meant with
“I fill up the tilemap with some code (parsing from the tmx file)”
basically this:
//lots of stuff before
if (tile.@gid != 0)
{
_map_Ground.setTile(tileX, tileY, uint(tile.@gid - 1));
}
//lots of stuff after
Sorry, I wasn’t paying attention. That won’t work because you’re passing a tilemap when it’s expecting a class. (I’m just restating the error, right?) It should be:
var groundlayer:Tilemap= new Tilemap(getScaledBitmapData(DUNGEON_1), 6);
I still get the
Incorrect number of arguments. Expected 5.
error
Oh, and won’t it just scale up the original tileset and add it to the world? What about “_map_Ground”?
What the function that the OP posted does is takes a source bitmap, upscales it, and returns it, where you can then declare an image/tilemap/spritemap/etc…, not scale up an actual Image(…)/Tilemap(…)/Spritemap(…)/etc…
Ahh…
Okay so I will do that first, then fill it up with the code.
But why do we get the error? requiring 5 arguments
var groundlayer:Tilemap= new Tilemap(getScaledBitmapData(DUNGEON_1), ARGUMENTS HERE REQUIRED);
Aha, I see.
I made this now
var groundlayer:Tilemap = new Tilemap(getScaledBitmapData(DUNGEON_1, 6), mapWidth * 128, mapHeight * 128, 128, 128);
but now I get this error:
Invalid BitmapData.
-.-
…
So it might be a memory issue.
And someone wrote this:
And if you find that it is actually a memory problem, besides wearing a new hat, you will have to rethink the way you cache those sprites...
So what am I supposed to do? If this doesn’t work, how in the flying **** am I supposed to scale these maps without running out of memory? The first map is 1920x1080 total, the sprites are 16x16… I want them to be 128x128… This shit should be simple
What about when I have huge maps? What should I do then?
Okay, so now I don’t understand what the hell is going on.
I figured the tileset was too big (since it was originally 480x480 and I wanted to scale it sixfold), so I went ahead and optimized the TMX file with a Tiled plugin. Basically you save the Tiled map in base64, run some magical python plugins, and it outputs two files.
Your original TMX file, but optimized (and still in base64), and a new tileset image. This tileset image only contains tiles that are actually being used by the TMX file.
So it’s basically a dream come true. Now, what I did was open the optimized file in Tiled, resaved it as XML (since I only know how to parse XML), and then we come to my game, which handles the scaling. Note that the new tileset image is only 96x96, and scaling it sixfold will make it “only” 576x576. I think that’s pretty damn good for an entire level.
So here we go, time to actually make it work with the game. F**k yeah! Oh wait, no! I still get the same “invalid” bitmapdata error. So is it even about memory? Is there some curse I have been carrying since birth? Is flashpunk disliking me as a user? What is going on here?
I will provide you with the entire source code of the gameworld (it handles the level loading), please take a look and see if you find any mistakes!
package game_handling
{
imports here
public class GameWorld extends World
{
[Embed(source="../assets/circle_gradient2.png")] public static const SPR_LIGHT_CIRCLE_GRADIENT:Class;
vars here, and:
private var _map_Ground:Tilemap;
private var _map_BG2:Tilemap;
private var _map_BG1:Tilemap;
public var collisionData:Grid;
//Level1
[Embed(source="../../levels/ConvertBase64/output/Level_1/level_1_xml.tmx", mimeType="application/octet-stream")]private const LEVEL1:Class;
[Embed(source="../../levels/ConvertBase64/output/Level_1/Dungeon_1.png")]private const DUNGEON_1:Class;
public function GameWorld()
{
}
override public function begin():void
{
super.begin();
doing some funky stuff here, and:
loadLevel1();
}
//Here comes the main code we want to correct:
public function loadLevel1():void
{
var groundlayer:Bitmap = new Bitmap(getScaledBitmapData(DUNGEON_1, 6));
var mapXML:XML = FP.getXML(LEVEL1);
var mapWidth:uint = uint(mapXML.layer.@width);
var mapHeight:uint = uint(mapXML.layer.@height);
var tileX:uint = 0;
var tileY:uint = 0;
collisionData = new Grid(mapWidth * 16, mapHeight * 16, 16, 16);
// Create a tilemap to show the level.
// Tile size is hardcoded, but could be pulled from the XML.
_map_Ground = new Tilemap(groundlayer, mapWidth * 128, mapHeight * 128, 128, 128);
_map_BG1 = new Tilemap(DUNGEON_1, mapWidth * 128, mapHeight * 128, 128, 128);
// Iterate through tiles, adding them to the tilemap.
for each (var tile:XML in mapXML.layer.data.tile)
{
// Once the end of the map is reached, loop back to the start.
if (tileX >= mapWidth)
{
tileX = 0;
tileY++;
}
//Ground
var tiles:String = mapXML.layer.attribute("name");
switch (tiles)
{
case "Ground":
if (tile.@gid != 0)
{
collisionData.setTile(tileX, tileY, true);
}
if (tile.@gid != 0)
{
_map_Ground.setTile(tileX, tileY, uint(tile.@gid - 1));
}
break;
case "BG":
if (tile.@gid != 0)
{
_map_BG1.setTile(tileX, tileY, uint(tile.@gid - 1));
}
break;
default:
trace("NOTHING")
}
// Move to the next tile.
tileX++;
}
//Objects
for each (var objectgroup:XML in mapXML.objectgroup)
{
var objectGroup:String = objectgroup.attribute("name");
switch(objectGroup)
{
//Spawn
case "Spawn":
for each (var object:XML in objectgroup.object)
{
var objectVar:String = objectgroup.object.attribute("name");
switch(objectVar)
{
case "Hero":
FP.world.add(new Hero(new Point(int(object.@x), int(object.@y))));
break;
default:
trace("no spawns")
}
}
break;
case "Chests":
for each (var chest:XML in objectgroup.object)
{
var chestVar:String = objectgroup.object.attribute("name");
switch(chestVar)
{
case "Wooden":
FP.world.add(new Chest_Wood(new Point(int(chest.@x), int(chest.@y))));
break;
default:
trace("no chests")
}
}
break;
default:
trace("unrecognized object type:", objectgroup.attribute("name"));
}
}
// Add the map to the world.
addGraphic(_map_Ground);
addGraphic(_map_BG1);
_map_Ground.scrollX
updateCollision();
}
public function updateCollision():void
{
var collision_:Collision = FP.world.getInstance("collision");
if (collision_ == null)
{
trace("no collision")
FP.world.add(new Collision(0, 0, _map_Ground, collisionData))
}else {
trace("updating collision")
}
}
public static function getScaledBitmapData(source:Class, scale:Number):BitmapData
{
var sourceBitmap:Bitmap = new source();
var sourceBitmapdata:BitmapData = sourceBitmap.bitmapData;
var matrix:Matrix = new Matrix();
matrix.scale(scale, scale);
var scaledBitmapdata:BitmapData = new BitmapData(sourceBitmapdata.width * scale, sourceBitmapdata.height * scale, true, 0x000000);
scaledBitmapdata.draw(sourceBitmapdata, matrix);
return scaledBitmapdata;
}
//End
}
}
Guys, please make a new topic for this discussion. You’re resurrecting an old thread with a discussion that’s only tangentially related.