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.

[SEMI-FILLED] Perspective Script

Rain

Sponsor

Hey guys, I'm looking for a script that I'm pretty sure used to exist.(although I'm not thatsure that I'm going to go and add it to the lost script thread)

The script I'm looking for is a perspective script to work with the SDK and the 'New Pixelmovement Script' by f0tz!baerchen. I need the script to be able to change the size of the character as he moves forwards and backwards (so that the further down the street he is for example the smaller he looks) also, if the script could include something that would allow me to focus the smallest point. (for example if my map does not have it's perspective totally aligned to the middle of the screen but say, slightly to the right or left with verifying levels of depth.)

http://img237.imageshack.us/img237/4171 ... opyur3.jpg[/IMG]

http://img404.imageshack.us/img404/1568 ... opyoo4.jpg[/IMG]
The red square on this image would be representative of the event that I could place to pinpoint the furthest point. (were the hero is smaller) The blue
lines are a rough representation of the perspective and the figure is obviously just the hero changing in size.

Being able to adjust the figures per map would be ideal, so that I could adjust by how much the hero shrinks or grows per step to fit better with the angle chosen for each map.



I'm pretty sure my description of this sucks and if you have any other questions feel free to PM me or just reply in here.

I'm not really sure what I can offer to anyone in return for doing this other than the usual name in credits, or maybe some artwork (better than the examples shown above anyway lol)


Thanks in advanced :thumb:
Camisado
 
I can do this as your Sponorship request.

Each map, you will be able to set a defined "focus position" and and value that will increase the size of the character according to that point.

Give me a bit to do a bit of research, as I know how it could be done, but I want to find how it could be best done.
 

Rain

Sponsor

SephirothSpawn;125527 said:
I can do this as your Sponorship request.

Each map, you will be able to set a defined "focus position" and and value that will increase the size of the character according to that point.

Give me a bit to do a bit of research, as I know how it could be done, but I want to find how it could be best done.


Wicked! Thanks SS, I knew there would be some benefit to sponsoring other than my flashy sponsor badge lol
 
I am not 100% satisified with it, but here's something I did in a few minutes:

Code:
class Game_Map
  # Map_id => [x, y]
  Perspective_Focus_Points = {
    1 => [256, -200]
  }
  Perspective_Scaling      = {
    1 => 400
  }
  attr_reader :focus_point
  attr_reader :scale_factor
  alias seph_spritepersp_gmap_setup setup
  def setup(map_id)
    @focus_point  = Perspective_Focus_Points.has_key?(map_id) ? 
      Perspective_Focus_Points[map_id] : nil
    @scale_factor = Perspective_Scaling.has_key?(map_id) ?
      Perspective_Scaling[map_id] : 1
    seph_spritepersp_gmap_setup(map_id)
  end
end

class Game_Character
  attr_reader :real_x
  attr_reader :real_y
end

class Sprite_Character
  alias seph_spritepersp_schr_update update
  def update
    seph_spritepersp_schr_update
    unless $game_map.focus_point.nil?
      if self.visible
        f_x, f_y = $game_map.focus_point[0], $game_map.focus_point[1]
        # Calculates X & Y Difference
        x_diff = (self.character.real_x / 4 - f_x).abs
        y_diff = (self.character.real_y / 4 - f_y).abs
        # Calculates Distance From Focus
        distance = Math.sqrt(x_diff ** 2 + y_diff ** 2)
        # Sets Zoom
        zoom = distance / $game_map.scale_factor.to_f
        self.zoom_x = zoom
        self.zoom_y = zoom
        # Centers Character
        self.ox = Integer(@cw * zoom / 2)
      end
    end
  end
end

Copy and paste and enjoy. I add things like event comments that can prevent the perspective and effect and such, but this is very basic.

How it works (I think XD)

It calculates the distance (in pixels) from the perspective focus to the event. From there, it takes the distance divides the scale factor and sets that to the zoom.

It's beyond basic, but works fairly well. I just don't like having to figure out decent scale factors and focus position, so I will try to come up with something more clever.
 

Rain

Sponsor

Sorry for sounding really noobish but how do I make this work?

Do I need to paste it into a new tab on the script editor or merge it some how with the other game_map one?

Also How do I activate it? When I create an event for it to focus on as a focus point I'm guessing I have to call that script is that correct? (plus how would I do that lol)

Sorry for being a bit dumb with this, and Happy new year ;)
 
Exactly. Any map ids not recorded have no perspecitive. And any non-defined map ids have a scale of 1.


Lets say your map is 20 * 15 and you want the sprites to be normal size at the very top, and double size at the bottom and the focus in the center.

20 / 2 * 32 = 320
15 * 32 = 480

so
Code:
  Perspective_Focus_Points = {
    1 => [320, -480]
  }
  Perspective_Scaling      = {
    1 => 480
  }

Now, at the very top of the the map in the center, characters will be normal sized and at the bottom their sized would be doubled. Bigger scales means smaller impact, so use huge numbers on bigger maps.
 

Rain

Sponsor

I'm not sure I understand this correctly because I keep getting a syntax error on line 5 (which is my new line added for the second map.)

Ok, so for my second map it's 20 by 20 and I want the focus point to be around the third tile from the bottom in the middle (give or take) so I need to go into the script editor and change the default ...
Code:
 class Game_Map
  # Map_id => [x, y]
  Perspective_Focus_Points = {
    1 => [256, -200] 
    }
  Perspective_Scaling      = {
    1 => 400

into....

Code:
 class Game_Map
  # Map_id => [x, y]
  Perspective_Focus_Points = {
    1 => [256, -200] 
    2 => [160, -640]
    }
  Perspective_Scaling      = {
    1 => 400
    2 => 1280   
    }



How I think this works


I'm guessing the 32 comes from being 32 pixels to a square right?

And also the minus number at the end of each => has to be doubled in the perspective_scaling?



Sorry for being really noobish about this but I've never learned anything about ruby or the script editor... (hmm maybe it's time lol)
 
Great Ideas!!!

I will do something like I did with my Encounter Areas script. You can control Rectangular and Circular regions, so when events are within an area, they have a different perspective focus and scale.

Here's an edit so you can read the focus and scale.

Code:
class Game_Map
  # Map_id => [x, y]
  Perspective_Focus_Points = {
    1 => [256, -200]
  }
  Perspective_Scaling      = {
    1 => 400
  }
  attr_accessor :focus_point
  attr_accessor :scale_factor
  alias seph_spritepersp_gmap_setup setup
  def setup(map_id)
    @focus_point  = Perspective_Focus_Points.has_key?(map_id) ? 
      Perspective_Focus_Points[map_id] : nil
    @scale_factor = Perspective_Scaling.has_key?(map_id) ?
      Perspective_Scaling[map_id] : 1
    seph_spritepersp_gmap_setup(map_id)
  end
  def focus_at?(x, y)
    return @focus_point[0], @focus_point[1]
  end
end

class Game_Character
  def perspective_zoom
    # Gets Focus Points
    f_x, f_y = $game_map.focus_at?(@x, @y)
    # Calculates X & Y Difference
    x_diff = (@real_x / 4 - f_x).abs
    y_diff = (@real_y / 4 - f_y).abs
    # Calculates Distance From Focus
    distance = Math.sqrt(x_diff ** 2 + y_diff ** 2)
    # Returns Zoom
    return distance / $game_map.scale_factor.to_f
  end
end

class Sprite_Character
  alias seph_spritepersp_schr_update update
  def update
    seph_spritepersp_schr_update
    unless $game_map.focus_point.nil?
      if self.visible
        # Sets Zoom
        zoom = @character.perspective_zoom
        self.zoom_x = zoom
        self.zoom_y = zoom
      end
    end
  end
end

I fixed the bug where for some reason, I did an offset (Don't know what I was thinking) and changed a bit and set somethings up for when I make the adjustments Myo suggested.

To access a character's zoom value, use
Code:
<game_character>.perspective_zoom
 

Mac

Member

That is amazing Seph, i thought it must be complex but then again i look at it and its mostly set co-ordinates and mathematical equations...i'm surprised someone didn't come up with this sooner.

Congrats on another amazing script...i'm loving it.
 

Mac

Member

Thats a neat idea cause even then if people can't be bothered to make a unique background they still can have that effect with normal tiles, nice! Keep it up!
 

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