Making an image larger then smaller with code
Posted: Fri May 23, 2008 4:17 pm
Hi, I've taken time out today from my main first project to amend a neat bit of code I found on the excellent RevNet site. The idea was that I'd "put this one under my belt" for a future project but after three or so hours of trying to get it to work, I've conceded defeat!!
The future project would be a Seek & Find type game, so that if a user clicks on a correctly found item, the image would become larger, smaller, larger and finally smaller again before disappearing. (Most of this type of games seem to have this added visual interest, as I'm sure you know...)
OK, here's the code I'm stuck on:
As it stands, DoSmall works fine, so does DoLarge on its own, but running both just gets the image floating off to nirvana!
I put in answer tRun and the surprising answer was just 1 less than the original value; I thought that by sending "DoSmall to me in 10 mill" was another type of loop, whereby the value of tRun would decrease by 1 every time. Obviously not! I guess this is why a repeat loop is no good, and why, even though DoSmall hasn't finished, DoLarge gets in on the act. (Or repeat loops and "send to me's" don't mix?)
I've tried lots of things to get them to run properly i.e finish DoSmall first before running DoLarge, but to no avail.
Although this isn't a pressing problem, i'd be most grateful for any explanations of my semi-questions in second para up, and some sort of solution please!

The future project would be a Seek & Find type game, so that if a user clicks on a correctly found item, the image would become larger, smaller, larger and finally smaller again before disappearing. (Most of this type of games seem to have this added visual interest, as I'm sure you know...)
OK, here's the code I'm stuck on:
Code: Select all
global tRun, tWidth, tHeight
on mouseUp pMouseBtnNo
--- cos of wrong coding, keeps wandering off!!!-------------
set the location of image "TestPic.png" to 217, 92
------------------------------------------------------------
put the formattedwidth of image "TestPic.png" into tWidth
put the formattedheight of image "TestPic.png" into tHeight
put 56 into tRun
DoSmall
wait 10 ticks
--DoLarge
--wait 10 ticks
--DoSmall
--wait 10 ticks
--DoLarge
--set the visible of image "TestPic.png" to false
-- etc
end mouseUp
on DoSmall
if tRun > 30 then
-- repeat with tRun =56 to 31
put tWidth - 1 into tWidth
put tHeight - 1 into tHeight
put tRun - 1 into tRun
set the height of image "TestPic.png" to round(tHeight * (tRun/tWidth))
set the width of image "TestPic.png" to round(tWidth * (tRun/tHeight))
-- end repeat
send "DoSmall" to me in 10 milliseconds
end if
--- test to see what tRun is: strange, thought it should be 31...... -----------
answer tRun
end DoSmall
on DoLarge
if tRun < 70 then
lock screen
put tWidth + 1 into tWidth
put tHeight + 1 into tHeight
put tRun + 1 into tRun
set the height of image "TestPic.png" to round(tHeight * (tRun/tWidth))
set the width of image "TestPic.png" to round(tWidth * (tRun/tHeight))
send "DoLarge" to me in 20 milliseconds
unlock screen
end if
end DoLarge
I put in answer tRun and the surprising answer was just 1 less than the original value; I thought that by sending "DoSmall to me in 10 mill" was another type of loop, whereby the value of tRun would decrease by 1 every time. Obviously not! I guess this is why a repeat loop is no good, and why, even though DoSmall hasn't finished, DoLarge gets in on the act. (Or repeat loops and "send to me's" don't mix?)
I've tried lots of things to get them to run properly i.e finish DoSmall first before running DoLarge, but to no avail.
Although this isn't a pressing problem, i'd be most grateful for any explanations of my semi-questions in second para up, and some sort of solution please!
