Forums

OverviewV-Play 1 Supportabout sprites & text over the top (button art & button text on top) › Reply To: about sprites & text over the top (button art & button text on top)

OverviewV-Play 1 Supportabout sprites & text over the top (button art & button text on top) › Reply To: about sprites & text over the top (button art & button text on top)
#6343

Michael

I have this as a general working solution (thanks to Alex for a past code tip for the button!), but I still have a minor issue:

import QtQuick 1.1
import VPlay 1.0

Item {
  id: button

  width: btnImg.width
  height: btnImg.height

  property alias text: buttonText.text
  property alias textColor: buttonText.color
  property alias textSize: buttonText.font.pixelSize

  signal clicked

  SingleSpriteFromFile {
    id: btnImg
    source: ma.pressed ? "btnGeneral-down.png" : "btnGeneral-up.png"
    filename: "img/wm.json"
    anchors.centerIn: parent
  }

  Text {
    id: buttonText
    anchors.centerIn: btnImg
    font.pixelSize: 14
    color: "white"
  }

  MouseArea {
    id: ma
    anchors.fill: btnImg
    onClicked: button.clicked()
  }

}

Inserting SpriteBatchContainer before the sprite buttons solves my problem for a simple layout (with just sprite and one rectangle serving as background colour), but I have another scene with many rectangles for visual layout purposes (3 rectangles within a column and each of these rectangles are serving as a container for a button & sprite image & text). When I use SpriteBatchContainer in this case, I can only seem to get the button text and the button sprite is lost (probably behind a rectangle). I guess I’m not understanding the SpriteBatchContainer use, or I need to rearrange the z-order of the rectangles, but then I’ll probably lose the convenience of the auto columnar layout with my current coding). I think I’ll give up & use the┬áMultiResolutionImage solution, as it sorts out the z-order issue nicely & automatically. I think it would be nice if you can add this ‘auto-z’ function to SingleSpriteFromFile, if possible as it’s much nicer to have the spritesheet.

Cheers, Michael.

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