Page 1 of 1
canvas collision question
Posted:
Thu Feb 17, 2011 11:31 pm
by Toasterman
I recently discovered the drawfrom function in a canvas, and how it HAS A SCALE! There is a bunch of neat stuff I'm thinking of doing with this (like having a mini version of the character on a terminal to look like a security feed).
Anyway, that made me wonder weather or not something drawn onto a canvas, either with drawfrom or just a line or pixel, could have it's own collisions. Instead of colliding with the whole big square of the canvas, can you detect a collision just with the things drawn inside?
I don't think there would be a way to do this, but I hardly know everything there is to know- anybody know if it is possible?
Re: canvas collision question
Posted:
Fri Feb 18, 2011 1:14 am
by Waluigiftw
Im pretty sure that anything drawn by the canvas technically becomes one actor so collisions wouldnt work, but i dont REALLY know everything im just PRETTY sure about that
Re: canvas collision question
Posted:
Fri Feb 18, 2011 2:37 am
by skydereign
The collision event is still for the entire canvas. But, if you are using draw_from, usually what you will just use it for scaling. So, you create the environment that you are drawing in some outside part of your game, and have the actual events triggered by the actor you are drawing. That probably didn't make a whole lot of sense, if so I can explain it further, though I think someone made a version of this as a demo.
Re: canvas collision question
Posted:
Fri Feb 18, 2011 6:34 am
by AnarchCassius
You could just create a canvas for each scaled actor and use those individually. Do not make the canvas bigger than you need to if you are going to use collision though, it eats cpu pretty quick. Then again I'm redrawing my actor every frame too... it's only a momentary special effect so it's okay.
Re: canvas collision question
Posted:
Fri Feb 18, 2011 10:48 pm
by Toasterman
Alrighty, I understand. I really didn't think there was a way to do it, just wanted to confirm before I dump a few ideas.
Thanks for the response though
Re: canvas collision question
Posted:
Thu Oct 24, 2013 11:48 pm
by 247wkman
look here: viewtopic.php?f=2&t=9427&p=93068#p93068
its the second time i've done a link to this, from another canvas themed queerie. i want to be able to scale actors to move into the distance or up to the screen, while being able to collide/interact as normal.
i learned how to refine the zoom example in the found post but there was a much more complex example posted a while ago (the 'new3d' one) and i cannot find the original post for hopes of further explanation so i put it there.
it entails a grass background with trees randomly created in the canvas using the y values to dictate scale. it has a movable character also drawn into the canvas and the CANVAS DRAW ORDER changes according to a formula that checks y value (i.e distance greater or smaller than tree object) to draw it infront or behind the trees.
the great thing about this file is it uses a 'if DRAWN' variable in the canvas draw event script that basically says: if this actor is drawn on screen, replace it with the canvas version.
i was actually fooled into thinking the canvas drawn actors had inherrited their collision abillities after adding such events in these actors. what was happening was that the original actors were still there, while the canvas was drawing the duplicuts on top of them (after all, the actors would have to be there for the 'if drawn' condition to apply- the fact that the actors themselves held the movement conditions, not the canvas was an overlooked hint too)
i have yet to figure out how 'drawn' works as i don't know code yet but this confirms any number of actors can be drawn in a single canvas and the draw order can be changed according to its interpreted value of distance.
the problem with canvas's inabillity to perform collision events inside itself could be addressed by having separate invisible collision actors- they would have simple scaling animations that would change to roughly mach the scaled actors they represent. its not a new thing to use separate collision actors with simpler boundries so the possibilty of sprites running towards/away or just resizing while still being able to bump into things is there.
the key elements are in the new3d example- the thing i would change would be to have the 'if drawn' code look at my collision actor (which would have the move instructions) and the image sprite would be drawn on top, tracting the collision sprites location and only holding animation change instructions.