PDA

View Full Version : sketch game



pantas
February 27th, 2009, 11:41 AM
hi there mates!
well... i ran across this amazing game http://www.gameshot.org/?id=2316 and tried to repicate some actions...

i got stuck in the part where nomather what we draw, that object will transform itself to a rectangle, square or circle...
how can this be done? anyone has any idea? tutorials?


thanks in advance,
cheers:pac:

cjke.7777
February 27th, 2009, 10:32 PM
Hey mate - we should be able to help. First as2 or as3? cs3 or cs4? And could you reword the question? What have you got so far? You can draw lines on the screen but not convert them to shapes?

pantas
March 5th, 2009, 09:11 AM
hi there! thanks for the reply!

i'm working on AS2, CS3 !

here goes the drawing part...


var contadorObjectos:Number = 0

var coresAR:Array = ["0xffff00", "0xffcc00", "0xff9900","0xff6600", "0xff0000", "0xff0066", "0xff00cc", "0xcc00ff",
"0x9900ff", "0x6600ff", "0x3300ff", "0x0099ff", "0x0066ff","0x00ffff", "0x00ff99", "0x66ff00", "0xccff00"]
var listenerClick:Object = new Object()
listenerClick.onMouseDown = function(){
trace("mouse down")
var novoObjecto:MovieClip = _root.createEmptyMovieClip("Objecto"+contadorObjectos, _root.getNextHighestDepth())
var desenho:MovieClip = novoObjecto.createEmptyMovieClip("desenho", novoObjecto.getNextHighestDepth())
novoObjecto._x = _xmouse
novoObjecto._y = _ymouse

desenho.lineStyle(5, coresAR[Math.round(Math.random()*(coresAR.length-1))], 100);
//desenho.beginFill(0xEEEEEE, 100)

desenho.onEnterFrame = function(){
this.lineTo(this._xmouse, this._ymouse)
}
novoObjecto.onPress = function(){
this.startDrag()
this.dragging = true
}
novoObjecto.onRelease = function(){
this.stopDrag()
this.dragging = false
this.onEnterFrame = activarGravidade
}
_root.ObjectoActual = novoObjecto
contadorObjectos++
}

Mouse.addListener(listenerClick);

listenerClick.onMouseUp = function(){
delete _root.ObjectoActual.desenho.onEnterFrame

_root.ObjectoActual.desenho.lineTo(0,0)
_root.ObjectoActual.desenho._x = -_root.ObjectoActual.desenho._width/2
_root.ObjectoActual.desenho._y = -_root.ObjectoActual.desenho._height/2
_root.ObjectoActual._y = _root.ObjectoActual._y - _root.ObjectoActual.desenho._y
_root.ObjectoActual._x = _root.ObjectoActual._x - _root.ObjectoActual.desenho._x
trace(_root.ObjectoActual.desenho._y)
// _root.ObjectoActual.endFill()
_root.ObjectoActual.pos.x = _root.ObjectoActual._x
_root.ObjectoActual.pos.y = _root.ObjectoActual._y
_root.ObjectoActual.radius = _root.ObjectoActual._height/2 - _root.ObjectoActual.desenho._y
_root.ObjectoActual.onEnterFrame = activarGravidade
_root.ObjectoActual = ""
}




now, the question was:
how can i check the drawing and convert it to a geometrical drawing?

if you check out that game, you will see what i mean.
when you draw something, it will check your drawing and replace it with a perfect geometrical object...

this is so cool :D

pantas
March 6th, 2009, 01:48 PM
anyone? please??

oldmanwinter
March 6th, 2009, 02:11 PM
i've never tried messing around with something like this, though after looking it over i think i'd try to code it maybe using these vague outlines-

first check to see if the line drawn intersects itself after the user lets go of the mouse button- if it does the user is trying to draw a circle or square, and if not they're drawing a line. if it doesn't intersect itself, just draw a line between the first and last points.

if it does intersect, average all the x and y values for each point of the looped line to find the center of the shape the person has drawn, and calculate the distance of each point in the line from the center. then go through these distances and check to see if they tend to increase and decrease (looking for four increases and decreases specifically) or if they're rather smooth. if the distance remains smooth, draw a circle with the average distance as the radius, and if it fluxiates 4 times, draw a rectangle with diagonals which are roughly equal to the peaks in distance times 2.

i'd have to put more thought into it to figure out how to do what i just mentioned specifically, and i think the guy that coded the game you linked used a simpler method (many times i'd try drawing a line and end up with a rectangle), but uh, hope that helps :)

pantas
March 12th, 2009, 10:57 AM
hmmm

nice point of view!
ill try this aproach...never thought about that. looks simple!

thanks for the reply oldmanwinter. that was really helpfull! :D

oldmanwinter
March 13th, 2009, 04:18 PM
hmmm

nice point of view!
ill try this aproach...never thought about that. looks simple!

thanks for the reply oldmanwinter. that was really helpfull! :D

hehe cool, glad i could help :D