canvas collision question

Non-platform specific questions.

canvas collision question

Postby Toasterman » Thu Feb 17, 2011 11:31 pm

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?
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

Re: canvas collision question

Postby Waluigiftw » Fri Feb 18, 2011 1:14 am

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 :mrgreen:
User avatar
Waluigiftw
 
Posts: 61
Joined: Mon Sep 06, 2010 2:49 pm
Location: Fox lake
Score: 3 Give a positive score

Re: canvas collision question

Postby skydereign » Fri Feb 18, 2011 2:37 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: canvas collision question

Postby AnarchCassius » Fri Feb 18, 2011 6:34 am

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.
AnarchCassius
 
Posts: 55
Joined: Sat Jan 29, 2011 1:33 am
Score: 6 Give a positive score

Re: canvas collision question

Postby Toasterman » Fri Feb 18, 2011 10:48 pm

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 :)
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

Re: canvas collision question

Postby 247wkman » Thu Oct 24, 2013 11:48 pm

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.
247wkman
 
Posts: 67
Joined: Mon Dec 13, 2010 3:55 pm
Score: 3 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest