Jump to content


Photo
- - - - -

Marquee Banners And Waving Flags


  • Please log in to reply
3 replies to this topic

#1 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 10 November 2008 - 06:24 PM

  • Title: Marquee banners and waving flags
  • Description: Easily make marquee banners and waving flags using primitives and paths
  • GM Version: GM 7
  • Registered: Yes
  • File Type: GMK
  • File Size: 109kb
  • File Link: http://host-a.net/ic...2b42/banner.gmk
Additional Info


Drawing marquee banners and waving flags is something that I always wondered how to do easily.

A marquee banner scrolls from left to right or right to left. While a flag flutter in the wind.

How to you set this up easily?

Using primitive triangle strip, you can setup a series a triangles that will define the shape of the banner or flag.

The texture mapping, a value from 0 to 1 for both u (left to right) and v (top to bottom) on the texture, is increased gradually from 0 to 1, for each triangle in the banner. If you set up say 100 triangles, you will have 100 uvs mapping 100 spots from left to right on the banner texture. The increment can be performed on u only for left to right, and the v value being 0 and 1 repeated over the length of the banner, you now have a strip of many triangles you can shape into a smooth looking banner.

To make the banner scroll, you simply need to change the uv mapping each draw to gradually move the texture inside the banner.

For example, if you have 2 triangle mapping a texture. From 0,0 0,1, 1,0 and 0,1, 1,0,1,1, if you decrease the u by .01, each draw, it will appear as though the banner is scrolling from right to left.

Defining how a banner or flag will look on the screen can be tedious as you have to define a lot of point that will translate into a series of triangle. BUT if you think about it, you can use the path system to make your banner.

You need 2 paths. 1 to define the top portion of the banner ribbon, another to define the bottom portion of the ribbon. The smoothing option of the path can turn you banner ribbon into any smooth shape you can think of.

Then you make a script that will loop though the 2 paths, getting the x and y value at an incremental position small enough to give smooth results while creating a ribbon using gm's primitive system.

Example loop
i = 0;repeat(100){    draw_vertex_texture(path_get_x(pathTOP,i),path_get_y(pathTOP,i)+yy,i,0)	draw_vertex_texture(path_get_x(pathBOTTOM,i)+xx,path_get_y(pathBOTTOM,i),i,1)	i+=.01;}

Note that getting the path x,y values this way, using the 0 to 1 method, gets coordinates in between actual path points. It's a very useful GM feature for paths, especially for smooth and closed paths. AND, being a value from 0 to 1, incremented by .01 gives 100 points for the strip AND the value is compatible for use for the u value of the uv map. Essentially, you kill 3 birds in one stone:

1) Make shape banner
2) Smooths the banner shape
3) Maps the uv with no headaches

The next part, the scrolling marky is solved by adding an offset to the u value


Create
off = 1;

Draw
i = 0;repeat(100){	draw_vertex_texture(path_get_x(pathTOP,i),path_get_y(pathTOP,i),i+off,0)	draw_vertex_texture(path_get_x(pathBOTTOM,i),path_get_y(pathBOTTOM,i),i+off,1)	i+=.01;}off-=.01;

Offset starts at 1, maps the texture outside GM's specs. The result is the triangle will be filled with the last pixel column of the texture. So make the texture transparent and make sure the texture has a transparent border all around to neutralize this behavior

The offset decreases, the marquee scrolls into view. When off is below 0, it scrolls out of view. When off is -1, it is done scrolling. Now the banner is filled with the pixel of the first column of the texture. Again, transparent border to fix this.


Flags fluttering in the wind or wiggling banner can be accomplished in a similar fashion. You use another path to define the wiggle.

i = 0;repeat(100){	draw_vertex_texture(path_get_x(pathTOP,i) + path_get_x(pathwiggle,i+off),path_get_y(pathTOP,i) + path_get_y(pathwiggle,i+off),i,0)	draw_vertex_texture(path_get_x(pathBOTTOM,i)+ path_get_x(pathwiggle,i+off),path_get_y(pathBOTTOM,i) + path_get_y(pathwiggle,i+off),i,1)	i+=.01;}off-=.01;

I simplified code to explain the concept. It's actually a little more complex than that. You see now the banner is created from the first 2 paths as before but now, each point is offset from a wiggle path which the position changes over time. the position is actually kept within 0 and 1 in the actual script and mapped according to position using frac.

Like mod can be used to make sure a value rang is respected

angle = angle mod 360

frac can be use the same way

off = frac(off) to maintain the value in the respected range
if(off>1) off = frac(off)

Here are the resulting 2 script



  • 0

#2 eafg2

eafg2

    GMC Member

  • GMC Member
  • 166 posts

Posted 11 November 2008 - 10:40 AM

Nice
  • 0

#3 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 17017 posts
  • Version:GM:Studio

Posted 13 August 2011 - 06:42 PM

Lovely! Another staff pick for you... Just please tidy up the formatting a little!
  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 13 August 2011 - 06:55 PM

Lovely! Another staff pick for you... Just please tidy up the formatting a little!


Yeah, that is the forum breaking up the code. it don't like my long lines

Hit reply if you want to grab the code properly formated
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users