Attach this behavior to a bitmap sprite this behavior uses one Global variable: newImage that is an image object that keeps a copy of each new image loaded in it used with the Revert button
--Attach this behavior to a bitmap sprite
--this behavior uses one Global variable: newImage that is an image object
--that keeps a copy of each new image loaded in it used with the Revert button
--grab a copy of the original bitmap and its rect so we can use the original button
on beginSprite me
originalImage=sprite(spriteNum).member.image.duplicate()
originalRect=sprite(spriteNum).rect
end
--on end set the sprite back to it's original state
on endSprite me
sprite(spriteNum).member.image=originalImage
end
--if newImage exists then revert back to it- otherwise revert to the original
on revert me
global newImage
if objectP(newImage) then
sprite(spriteNum).member.image=newImage
else
sprite(spriteNum).member.image=originalImage
end if
end
--set the sprite to it's undo image
--undo image is set at the beginning of mouseDown
on undo me
if objectP(undoImage) then
sprite(spriteNum).member.image=undoImage
end if
end
--set the sprite back to it's original image and rect
--set newImage and undoImage to zero
on original me
global newImage
sprite(spriteNum).member.image=originalImage
sprite(spriteNum).rect=originalRect
newImage=0
undoImage=0
end
on mouseDown me
global distRange
undoImage=sprite(spriteNum).member.image.duplicate()
upperLeft=point(sprite(spriteNum).left,sprite(spriteNum).top)
fromCursor=distRange/2
mPoint=the mouseLoc
memPoint=mPoint-upperLeft --gives us the click loc in the member
--Check to ensure the edges of the retange we grab don't lie outside the
--extents of the image
mMinFrom1=memPoint[1]-fromCursor
if mMinFrom1<0 then mMinFrom1=0
mMinFrom2=memPoint[2]-fromCursor
if mMinFrom2<0 then mMinFrom2=0
mPlFrom1=memPoint[1]+fromCursor
if mPlFrom1>sprite(spriteNum).member.rect[3] then mPlFrom1=sprite(spriteNum).member.rect[3]
mPlFrom2=memPoint[2]+fromCursor
if mPlFrom2>sprite(spriteNum).member.rect[4] then mPlFrom2=sprite(spriteNum).member.rect[4]
--define original rects around cursor click point
--these rects are in member coords
r1=rect(mMinFrom1,mMinFrom2,memPoint[1],memPoint[2])
r2=rect(memPoint[1],mMinFrom2,mPlFrom1,memPoint[2])
r3=rect(memPoint[1],memPoint[2],mPlFrom1,mPlFrom2)
r4=rect(mMinFrom1,memPoint[2],memPoint[1],mPlFrom2)
--create new images based on the above rects
r1Image=image(r1[3]-r1[1],r1[4]-r1[2],32)
r2Image=image(r2[3]-r2[1],r2[4]-r2[2],32)
r3Image=image(r3[3]-r3[1],r3[4]-r3[2],32)
r4Image=image(r4[3]-r4[1],r4[4]-r4[2],32)
--now copy pixels from the member into the new images
mI=sprite(spriteNum).member.image
r1Image.copyPixels(mI,r1Image.rect,r1)
r2Image.copyPixels(mI,r2Image.rect,r2)
r3Image.copyPixels(mI,r3Image.rect,r3)
r4Image.copyPixels(mI,r4Image.rect,r4)
repeat while the stillDown
x=the mouseLoc-upperLeft --current pos in the member
if x[1]>r1[1] and x[1]r1[2] and x[2] r1Quad=[point(r1[1],r1[2]),point(r1[3],r1[2]),the mouseLoc-upperLeft,point(r1[1],r1[4])]
r2Quad=[point(r2[1],r2[2]),point(r2[3],r2[2]),point(r2[3],r2[4]),the mouseLoc-upperLeft]
r3Quad=[the mouseLoc-upperLeft,point(r3[3],r3[2]),point(r3[3],r3[4]),point(r3[1],r3[4])]
r4Quad=[point(r4[1],r4[2]),the mouseLoc-upperLeft,point(r4[3],r4[4]),point(r4[1],r4[4])]