Forums

OverviewV-Play 1 Supportrotation: how to get same transformOrigin for item and collider? › Reply To: rotation: how to get same transformOrigin for item and collider?

OverviewV-Play 1 Supportrotation: how to get same transformOrigin for item and collider? › Reply To: rotation: how to get same transformOrigin for item and collider?
#5762

Alex
V-Play Team

Hi Heini,

you will also have to modify the position of your sprite and the collider inside the entity.

import QtQuick 1.1
import VPlay 1.0
import Box2D 1.0

EntityBaseDraggable {
  id: obstacle
  entityType: "obstacle"
  width: image.width;
  height: image.height

  selectionMouseArea.anchors.fill: image
  clickingAllowed: true
  colliderComponent: collider

  SpriteSequence {
    id: image
    width: 32
    height: 32
    x: -width/2
    y: -height
    spriteSheetSource: "../img/squaby-spritesheet.png"

    Sprite {
      name: "walk"
      frameWidth: 32
      frameHeight: 32
      frameCount: 4
      startFrameColumn: 1
      frameRate: 20
    }
  }

  PolygonCollider{
    id:collider
    bodyType: Body.Static
    x: -image.width/2
    y: -image.height
    vertices: [
      Qt.point(0, 0),
      Qt.point(31, 0),
      Qt.point(31, 31),
      Qt.point(0, 31)
    ]
  }

  onEntityClicked: {
    obstacle.rotation += 10
  }
}

Moving everything up its height, and half its length to the left will move the rotation origin to the bottom center of all the items.

Is this solution sufficient for you?

Cheers,
Alex

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