[XP] [VX] Create viewports in any way

Started by newold, August 11, 2011, 09:38:14 am

Previous topic - Next topic

newold

August 11, 2011, 09:38:14 am Last Edit: August 11, 2011, 01:42:10 pm by newold
Viewport_Mask
Authors: Newold
Version: 1.0
Type: VIEWPORT ADDON
Key Term: Misc Add-on



Introduction

With 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




Demo

Demo for XP:

http://www.megaupload.com/?d=C7X9YH09 or
http://www.mediafire.com/?ivda939v8ba5mvy


Demo for VX:

http://www.megaupload.com/?d=GMMPHMZR or
http://www.mediafire.com/?zb4ebkcp4asaqzb



Script



Instructions

The 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



Compatibility

100% compatible with XP and VX


Credits and Thanks


  • me  8)




Author's Notes

I 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  :^_^':

ForeverZer0

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.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

newold

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



ForeverZer0

Ah, I see.  I didn't look through it close enough. :facepalm:
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

AngryPacman

G_G's a silly boy.