Viewport_Mask
Authors: Newold
Version: 1.0
Type: VIEWPORT ADDON
Key Term: Misc Add-on
IntroductionWith this script you can use viewports non-reactangular (Circle viewport for example)
Features
- Create viewports non-rectangular easily
- You can animate bitmap in this viewports as planes (see example in demo)
Screenshots(http://img825.imageshack.us/img825/2838/30388558.jpg) (http://imageshack.us/photo/my-images/825/30388558.jpg/)
DemoDemo for XP:
http://www.megaupload.com/?d=C7X9YH09 (http://www.megaupload.com/?d=C7X9YH09) or
http://www.mediafire.com/?ivda939v8ba5mvy (http://www.mediafire.com/?ivda939v8ba5mvy)
Demo for VX:
http://www.megaupload.com/?d=GMMPHMZR (http://www.megaupload.com/?d=GMMPHMZR) or
http://www.mediafire.com/?zb4ebkcp4asaqzb (http://www.mediafire.com/?zb4ebkcp4asaqzb)
Script
InstructionsThe instructions are in spanish in the script, (the script in the demo is called **Masks**) here I put the instruction in english (google translate and superviced by me, but may contain errors in grammar). You can to put this script anywhere in the script's editor in your project
Instructions translate in English
=begin
-------------------------------------------------- ---------------------------
By newold
08/10/2011
-------------------------------------------------- ---------------------------
This script will create viewport for sprites in any way
(circle, triangle, irregular polygon...).
-------------------------------------------------- ---------------------------
Use:
The script load images from folder that will contain viewport-mask.
(Any non-transparent part of these images will be deleted on the image
sprite)
Once you've created your sprite and you've assigned a picture, you can apply
this new viewport like this:
your_sprite.mask = Viewport_Mask.new ("Name of pattern of the viewport")
Automatically, the image of the sprite will be resized to size of the image
pattern, and it will look as form of the pattern.
To move the image on the new viewport, use this command:
your_sprite.ani_mask(Speed X, Speed Y)
the image will move as if it were a plane
******************************************************************************
Tutorial to create pattern in Photoshop:
******************************************************************************
1 - Create a new image.
2 - Draw the desired shape of the viewport with a solid color
(Eg: #000000)
3 - Once created the pattern, you pressed press "Left click" on
the image in the layers palette with "CTRL" pressed, to select your pattern.
4 - Press "delete/Back" to delete the pattern.
5 - Press CTRL + SHIFT + I to invert the selection
6 - Take the paint with a solid color (Eg: #000000)
7 - Fill the selection
8 - Save the pattern as png in the pictures folder of your game
9 - Now you can use this pattern to create a viewport with him.
******************************************************************************
=end
Compatibility100% compatible with XP and VX
Credits and Thanks
Author's NotesI leave to your imagination the use that you could to give to this script in yours proyects... (circle mini-maps perhaps?)
PS: sorry for the grammar and spelling mistakes :^_^':
I'm curious why you just didn't apply some simple trig to check if the coordinates are within the circle. You can greatly reduce the number of calculations. Maybe something like this.
class Circle
def initialize(center_x, center_y, radius)
@center_x = center_x
@center_y = center_y
@radius = radius
end
def in_area?(x, y)
square_dist = (@center_x - x) ** 2 + (@center_y - y) ** 2
return square_dist <= @radius ** 2
end
end
This is much easier, though it could probably be done even more efficient than that. Its the general idea, though you will have to apply it to how you are using it.
my script not only serves to create circular viewport.
Your code works on circular viewports but would not work to create other forms of viewports.
In this picture you can see different viewports that can be created with my script
(http://img163.imageshack.us/img163/9381/sinttulo1qh.jpg) (http://imageshack.us/photo/my-images/163/sinttulo1qh.jpg/)
Ah, I see. I didn't look through it close enough. :facepalm:
That's cool. Great job!