Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Skewing a Sprite

How would I go about doing this? Say I wanna take a flat square like this:

Code:
_____________
|             |
|             |
|             |
|             |
|             |
|             |
---------------

and turn it into this:

Code:
     /|
    / |
   /  |
  |   |
  |   |
  |   |
   \  |
    \ |
     \|


How would I do that?
 
With difficulty. I'm sure there are people working on it, but it's the kind of thing you would normally do with some kind of hardware support. If you really really need to, you would take each colomn as a Rect and stretch blt it onto a new bitmap. Alternatively, you could split each colomn of pixels into a seperate Sprite and use the zoom function on them.
 
Just treat it pixel by pixel. A little math you could do it fairly easily.

I suggest making a dump bitmap and just use rectangle blt transfers. You just have to go about it logically (and possibly some trig)

You can see in this method that I used in the Shift Puzzle's Game:
Code:
#==============================================================================
# ** Bitmap
#==============================================================================

class Bitmap
  #--------------------------------------------------------------------------
  # * Rotate Square 90 Degree Increments
  #--------------------------------------------------------------------------
  def sqr_rotate_90(degrees = 90)
    # If Degrees is Greater than 360
    degrees -= 360 until degrees < 360
    # If Degrees is Less than 0
    degress += 360 until degrees >= 0
    # Duplicates Self
    dummy = self.dup
    # Passes Through all Pixels on Dummy Bitmap
    for i in 0...self.height
      for j in 0...self.width
        # Configures destination Pixel Coordinates
        case degrees
        when 90  ; x, y = width - i - 1, j
        when 180 ; x, y = width - j - 1, height - i - 1
        when 270 ; x, y = i, height - j - 1
        else     ; return
        end
        # Reset Pixel
        self.set_pixel(x, y, dummy.get_pixel(j, i))
      end
    end
  end
end

This actually works pixel by pixel, but it starts with making a dummy bitmap and transfering pixels that route.

What you need is something that will stretch_blt.

http://img139.imageshack.us/img139/9195/examplegk4.png[/img]

That is essentially all you are doing. Just start from the left of your actual bitmap and move right, stretching the bitmap to fit that area.

If you need an example, I can work up something (maybe even a method of doing something like this.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top