1

I need this image to, upon button press, rotate 90 degrees to the left, and upon a different button rotate 90 degrees to the right. here is my code. Any help would be greatly appreciated!!

var pinWheel = new SMF.UI.Image({
    name :"Pin Wheel",
    image : "assets://pin_wheel.png",
    positionBackgroundImage : "CENTER",
    top : "60%",
    imageFillType: SMF.UI.ImageFillType.ASPECTFIT
});
Binary111
  • 163
  • 3
  • 14

1 Answers1

2

SMF.Bitmap has static functions for image processing. rotate function will help you about your question.

Here is a sample code for you:

var img = new SMF.UI.Image({
  name: "img",
  image: "smartface.png",
  left: "15%",
  top: "20%",
  width: "70%",
  height: "10%",
  imageFillType: SMF.UI.ImageFillType.ASPECTFIT
});

var btn = new SMF.UI.TextButton({
  name: "btn",
  text: "Rotate!",
  onPressed: function() {
    var myImageUri = "smartface.png";
    var im = new SMF.Bitmap({
      imageUri: myImageUri,
      onSuccess: function(e) {
        im.rotate({
          angle: 90,
          format: SMF.ImageFormat.PNG,
          compressionRate: 0.7,
          onSuccess: function(e) {
            img.image = e.image;
          },
          onError: function(e) {
            alert("Error: " + e.message);
          }
        });
      },
      onError: function(e) {
        alert("Error: " + e.message);
      }
    });
  },
  left: "15%",
  top: "70%",
  width: "70%",
  height: "10%"
});
halit
  • 177
  • 7
  • So this works, which is absolutely amazing, but there appears to be some sort of lag or transition that I would like to remove. I appreciate all the help so far, but any idea how I can do this as well? – Binary111 Jan 12 '17 at 17:25
  • @Binary111 SMF.Bitmap functions works asynchronously, most probably this seems as lag to you and I don't think you can do anything for it. You may show activity indicator (if rotating takes that much time) for better UX. – halit Jan 13 '17 at 12:30
  • oh okay, thanks for the help! Its a game so I need quick response, but i think i can add a new image that was previously rotated and remove the one underneath. – Binary111 Jan 13 '17 at 13:21