Switch to full style
Understanding the language, error messages, etc.
Post a reply

Is there a general fill() function?

Sat Apr 19, 2014 8:08 pm

I am working on a game concept where I need to draw a lot of trapezoids.
I would like to fill four lines to form a solid trapezoid.
Something like this:
Code:
gb.display.beginPath();
gb.display.drawLine(xStart, yStart, xEnd, yEnd); //line1
gb.display.drawLine(xStart, yStart, xEnd, yEnd); //line2
gb.display.drawLine(xStart, yStart, xEnd, yEnd); //line3
gb.display.drawLine(xStart, yStart, xEnd, yEnd); //line4
gb.display.fill();


Is there a general fill() function or something similar?

Re: Is there a general fill() function?

Sat Apr 19, 2014 8:14 pm

You can split you trapezoid in two triangles to be able to use the following function:
Code:
fillTriangle(x0, y0, x1, y1, x2, y2);

Re: Is there a general fill() function?

Sat Apr 19, 2014 9:07 pm

This will work as well. Thanks

Re: Is there a general fill() function?

Sat Apr 19, 2014 9:15 pm

You're welcome :)
I never used this function yet, I don't know how efficient it is. when you say that you have to draw a lot of trapezoid, what do you mean by a lot ?
Just out of curiosity, what is your game about?

Re: Is there a general fill() function?

Sat Apr 19, 2014 9:49 pm

It is not that spectacular.
I want to create a pseudo 3D engine (like Outrun or Hang On).
It was one of the first things that came to my mind after seeing the Gamebuino project.
The proper 3D engine has already been done by myndale so I am going for pseudo 3D.
It will feature hills and slopes and uses said trapezoids for the terrain.

I don't know if my method is very efficient (there are several approaches) and we will see if it works well on the device. For now I am going to prototype the engine in JS and will port it later.

Image

Re: Is there a general fill() function?

Sat Apr 19, 2014 9:56 pm

u may be able to do something similar to scanline but ur triangulation may work better

bit of a side-track but worth looking into there is a race game called v-rally thats has a gameboy port wich has ur graphics style

Image

Re: Is there a general fill() function?

Sat Apr 19, 2014 10:18 pm

Awesome, having nostalgic flashbacks to Pole Position now :) Looking forward to seeing what you come up with!

Re: Is there a general fill() function?

Sat Apr 19, 2014 10:24 pm

The line approach tends to look a bit frayed but it sure is an alternative.
Here is a nice article on pseudo 3d engines.

http://www.extentofthejam.com/pseudo/

@myndale
could you test the performance of triangle scaling if you are bored or something (no hurry)
:)

Re: Is there a general fill() function?

Sat Apr 19, 2014 10:27 pm

I was going to raise that same article :o
IT is a great read and should help that front.

Re: Is there a general fill() function?

Sat Jul 26, 2014 5:16 pm

Heres another good article with a break down of elements. http://codeincomplete.com/posts/2012/6/ ... ipt_racer/


Good luck, would love a Hang on clone :D
Post a reply