Question about "canvas" and some others..

37 views
Skip to first unread message

Moshe Adriano Yosef Feit

unread,
Apr 26, 2016, 8:54:24 AM4/26/16
to HaxeFlixel
Hi,

I'm a little confused about canvas and some other thing.

1. Which one is true about canvas (where Pink is the canvas):


Say, I want to make a new Trapezoid every time user pressed direction (UP, LEFT, RIGHT, DOWN) - Assume the Trapezoid is a class, like Player class.
Is it (a) I only need one canvas, then use that one to draw the next trapezoid? or (b) I have to make canvas for each trapezoid with width and height prespective to width/height of the trapezoid, begin draw, then add(trapezoid) in the PlayState?
  • If (a), does the Trapezoid controlable? If yes, then I have to update each point (since drawPoly uses vertices) and redraw, or just call the redraw method?
  • If (b), does this canvas act as 'collision colider'?
2.Also, what's the different between makeGraphic() and drawRect() etc. ? Isnt drawRect() also 'make graphic' ?

3. Talking about collision collider,

If canvas doesn't act as collider, how to add the collider?
I'm confused, close to know nothing about this. Because many examples uses graphics (such as PNG) and haven't found a game or example that uses this drawxxx() method as its 'graphic'.

When you add the collider, which one is true? Where grey is collision collider.


Also, because there is method getMidPoint(). Look at the picture below.

Suppose I the graphic is a PNG (the arrow). By getMidPoint(), I can get the mid point of it (red). Say from the mid point, I can find the coordinate of each angels(Yellow).
Then, I wanted to add the collision colider unto the grey area only, instead of the whole arrow. Is it possible?

I'm sorry I asked too much - really! 
Thank you!!

Moshe Adriano Yosef Feit

unread,
Apr 27, 2016, 5:53:10 AM4/27/16
to haxef...@googlegroups.com
Never mind, too many errors in the cheat sheet, tutorial, and others.
Which makes me confused all the time...

Claudio Ficara

unread,
Apr 27, 2016, 7:18:25 PM4/27/16
to HaxeFlixel
Too many questions to address, but basically, the flixel canvas is where everything is painted, and what you would have there would be 3 individual sprites. You don't need to know the internals of haxeflixel in order to work with it. Just add your clases, which extends from FlxSprite by using add() on your FlxState.

Now, as for collision, you have a few options. If you wanna do a overlap (check if object is above other) use FlxG.overlap, if you need to make them collide using the bounding boxes of the image (the dimensions, the whole rectangle), you use FlxG.collide. If you wanna do a check to see what pixels of your image are overlaping other pixels, you need to use a pixel overlap function (can't remember the name).

Now if you want to do a complex collision of these arrows, you need physics, haxeflixel uses nape, which is great. But if you only want to do a simple collision with the box of the arrow you specified, then you have to manually adjust the width and height, and the corresponding offset.
Reply all
Reply to author
Forward
0 new messages