Is there a general fill() function?

Understanding the language, error messages, etc.

Is there a general fill() function?

Postby phi » 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: Select all
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?
User avatar
phi
 
Posts: 50
Joined: Sun Mar 23, 2014 1:48 pm
Location: Germany

Re: Is there a general fill() function?

Postby rodot » Sat Apr 19, 2014 8:14 pm

You can split you trapezoid in two triangles to be able to use the following function:
Code: Select all
fillTriangle(x0, y0, x1, y1, x2, y2);
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Is there a general fill() function?

Postby phi » Sat Apr 19, 2014 9:07 pm

This will work as well. Thanks
User avatar
phi
 
Posts: 50
Joined: Sun Mar 23, 2014 1:48 pm
Location: Germany

Re: Is there a general fill() function?

Postby rodot » 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?
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Is there a general fill() function?

Postby phi » 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
User avatar
phi
 
Posts: 50
Joined: Sun Mar 23, 2014 1:48 pm
Location: Germany

Re: Is there a general fill() function?

Postby adekto » 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
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: Is there a general fill() function?

Postby Myndale » Sat Apr 19, 2014 10:18 pm

Awesome, having nostalgic flashbacks to Pole Position now :) Looking forward to seeing what you come up with!
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Is there a general fill() function?

Postby phi » 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)
:)
User avatar
phi
 
Posts: 50
Joined: Sun Mar 23, 2014 1:48 pm
Location: Germany

Re: Is there a general fill() function?

Postby erico » 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.
User avatar
erico
 
Posts: 671
Joined: Thu Mar 27, 2014 9:29 pm
Location: Brazil

Re: Is there a general fill() function?

Postby Limited » 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
Limited
 
Posts: 13
Joined: Sat May 31, 2014 7:25 pm


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 14 guests

cron