Forums

OverviewV-Play 1 Support › SingleSpriteFromFile gets scaled to 0.5

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #6695

    s4ge

    I’m using a sprite sheet generated by the texture packer, here is it’s json source:

     

    <code class="language-qml">{"frames": {
    
    "brick-hd.png":
    {
    	"frame": {"x":2,"y":2,"w":44,"h":44},
    	"rotated": false,
    	"trimmed": false,
    	"spriteSourceSize": {"x":0,"y":0,"w":44,"h":44},
    	"sourceSize": {"w":44,"h":44}
    }},
    "meta": {
    	"app": "http://www.codeandweb.com/texturepacker ",
    	"version": "1.0",
    	"image": "textures.png",
    	"format": "RGBA8888",
    	"size": {"w":64,"h":64},
    	"scale": "1",
    	"smartupdate": "$TexturePacker:SmartUpdate:36c3e6127ca7935d11da3ac8c93cdd04:32c4e4a0b3f879bac602e5838702b49c:cf827d152df04949dfee256cd0c8efd8$"
    }
    }
    

     

     

    Then i setup an entity which holds a single sprite:

     

    <code class="language-qml">SingleSpriteFromFile {
    
            id: sprite
    
            source: "brick-hd.png"
    
            filename: "../../graphics/textures.json"
    
            anchors.fill: brick
    
        }
    
    

     

    When i draw this sprite, it gets scaled down to 22px instead of 44px, which is an unpleasant behavior. If i use rectangles instead of sprites, everythings works like expected.

    #6696

    s4ge

    I noticed that the sprites actually in correct size, but they draw with a gap. Heres is my code which i use to draw a grid of bricks:

     

    <code class="language-qml">    function initialize(levelData){
            var x, y
    
            entityManager.removeEntitiesByFilter("brick")
    
            brickContainer.width = levelData.data.length * 22
            brickContainer.height = levelData.data[0].length * 22
            brickContainer.x = (levelScene.width - brickContainer.width) / 2
            brickContainer.y = (levelScene.heigth - brickContainer.heigth) / 2
    
            for(x = 0; x < levelData.data.length; x++){
                for(y = 0; y < levelData.data.length; y++){
                    entityManager.createEntityFromUrlWithProperties(
                        Qt.resolvedUrl("../entities/Brick.qml"),
                        {
                            x: (levelData.data.length - x - 1) * 22,
                            y: (levelData.data[x].length - y - 1) * 22,
                            isEmpty: levelData.data[x][y] === 0,
                            levelScene: levelScene
                        }
                    )
                }
            }
    
            initialized();
        }

     

    Prevoiusly, i drawed them by * 44, but that made a gap of 22 which i could not really understand, since the sprite are 44×44 pixel in size. If i draw rectangles using * 44, everythings works like i expect. Do i miss something?

    #6701

    Alex
    V-Play Team
    #6705

    s4ge

    Hi Alex,

    yes I followed the TexturePacker tutorial.

    Your example is working just fine, the difference is that your entity isn’t created “at runtime”. I figured out that the scene scale seems to play a big role. For example, when i launch die application, the x scale of the scene is 2, since im using the default window size of 960×640 and the default scene size of 480×320.

    Using this information, i tried something on my javascript loop which generates my grid of entities:

     

    <code class="language-qml">    function initialize(levelData){
            var i, x, y, xSize, ySize
    
            xSize = 44 / levelScene.xScaleForScene
            ySize = 44 / levelScene.yScaleForScene
    
    
            entityManager.removeEntitiesByFilter("brick")
    
            brickContainer.width = levelData.data.length * xSize
            brickContainer.height = levelData.data.length * ySize
            brickContainer.x = (levelScene.width - brickContainer.width) / 2
            brickContainer.y = (levelScene.height - brickContainer.height) / 2
    
            for(x = 0; x < levelData.data.length; x++){
                for(y = 0; y < levelData.data[x].length; y++){
                    entityManager.createEntityFromUrlWithProperties(
                        Qt.resolvedUrl("../entities/Brick.qml"),
                        {
                            entityId: "brick_" + y + "_" + x,
                            x: (levelData.data.length - x - 1) * xSize,
                            y: (levelData.data[x].length - y - 1) * ySize,
                            isEmpty: levelData.data[x][y] === 0,
                            levelScene: levelScene
                        }
                    )
                }
            }
    
            initialized();
        }

     

    As you can see, i now take the current scene scale into account when i set the position of each brick entity and it works just perfect, even if i change the resolution at runtime. However, i wouldn’t expect that, since an object inside of an scaled object should transform it’s child positions automatically, shouldn’t they?

    #6719

    Christian
    V-Play Team

    Hi,

    sprites get auto-scaled if they are put into a scene. I guess you put your entities inside scenes? If you create the entities at runtime, did you set the correct entityContainer for entityManager to be inside of a Scene?

    Internally you can then always work with the “logical scene size” of 480×320 or 320×480 (if your game is portrait).

    Cheers,

    Chris

     

    #6720

    s4ge

    Hi Christian,

    the entity container is placed inside of the scene, the same scene defines the creation functions shown above, which dynamically generates the entities.

    Since the entity container is inside my scene, and my scene size is 480×320, everythings should be finde if i place my 44×44 sprites every 44 pixels (loopVar * 44). But instead, i get a gap of exactly 44 pixels so twice of the position i gave, and the scale of the scene is 2.0 on the x axis. Now i place my entities taking the scale into account (x = loopVar * (44 / sceneXScaleforWindowHowever)). This works perfect so far, but i cant believe that this should be the default behavior. Could there be a delay between the scaling of the scene and my entity creation? Maybe i should let you know that the scene which holds the entities if neither visible or set as active scene when the entities become created.

    #6721

    Christian
    V-Play Team

    Hi,

    you are right this is not an expected behavior – usually you should be able to work with the logical scene size without the need to use the sceneScale.

    Can you please post a complete QML example here which contains the entity creation part and your main qml file which we can then try in Qt Creator?

    Also, please try without a SingleSpriteFromFile but with Rectangles if it works then (for narrowing down if it is a problem with SingleSpriteFromFile or somewhere else).

    Cheers,
    Chris

    #6723

    s4ge

    Hi Christian,

    as already said above, i can allready let you know that the problem does NOT occour with simple rectangles, so it seems to be a problem with the SingleSpriteFromFile component. I will post an example of the code asap.

    #6724

    s4ge

    Hi,

    I decided to upload the whole project. Here is the link: http://jeanpascal.de/Picross.zip

    To get to the scene, just launch the projekt and click on “Load Level 1”, the bricks which fading in are our small friends.

     

    To see the behavior of them when i do NOT scale their positions, just changes the lines in scenes/LevelScene.qml:209-210 to a static value of 44.

    If you want to see that Recangles work correctly with these static values you have to change the entity lines in entities/Brick.qml:35-41 to a simple Recangle component with the id “sprite”. The PropertyChanges settings of the entity may brake then, but i guess you can just remove them for testing.

     

    And please let me know when you have downloaded the archive, i would like to remove it again.

    • This reply was modified 4 years, 5 months ago by  s4ge.
    #6726

    s4ge

    I guess i was able to isolate the problem.

    I now added a new entity, which has the same dimensions as the bricks, but displays numbers on a rectangle.

    These entities are renderer at the double size of the bricks so (bricksize * sceneScale, and we know that scene scale is 2).

    This leads the to the question, “Why are the brick sprites are not scaled up and renderer at their orignal 44×44” ?

    #6727

    Christian
    V-Play Team

    Alright thanks, we’ll have a look at it!

    #6731

    Christian
    V-Play Team

    Hi,

    your hd texture is 44×44 big. This means the sprite will be 22×22 in the “logical scene size” of 480×320. For a 44×44 image in sd size, the hd image would need to be 88×88 big. Does this explain your issue?

    Cheers, Chris

    #6733

    s4ge

    Does that mean that if i have a sprite, which physical size is 44×44, that i cant place them every 44 pixels through a loop? That is the actual problem. I mean, as you can see when you run my project, the sprites ARE 44×44 rendered, but i cant place them every 44 pixels without having a gap of 44 pixels. on the other hand, when i draw rectangles which are 44×44, they become double sized (in the same scene where the sprite dimensions still being unscaled, but the coordinates ARE scaled), and also can’t place them every 44 pixels, instead i have to place them every 88 pixels. Seems like there is no “normalized” behavior of the scaling between native components and loaded images.

     

    Edit: Well i guess i got the problem/understood what i used to not understand. Will an entity without explicit size auto grow on its child dimensions? This way, i could read out the size for my loop dynamically.

    • This reply was modified 4 years, 5 months ago by  s4ge.
    #6736

    Christian
    V-Play Team

    An entiy has no size by its definition (it is only a container of children components). However, you can set your entity width to sprite.width and you are then able to read the entity size after you created it in your logic. Note that the width of the Sprite will always be the “logical size” aka the sd size, so in your case 44px (when the hd images are 88px big due to the content scaling and the sd are 44px). Does this solve your question?

    Cheers, Chris

Viewing 14 posts - 1 through 14 (of 14 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support