Trying to achieve two simple effect that is common in casual games.

Hi,

I’m trying to make some effects that is common in casual games. They seem simple but I don’t know how to chain all those small simple things together. I was thinking of using several timer.performWithDelay but I couldn’t get my head around it properly.

1- First one is counting score. In most casual games, when player’s score is for example 1000 and he gets 100 score, it’s score does not instantly go to 1100 but starts to count from 1000 to 1100 in like 2-3 seconds and thus it feels better.

How can I do this?

2- Second effect I want to do is when there are some text are drawn on the screen: A) They appear on the screen, B) in like half a second it gets 2-4 sizes bigger and then in like another half second it gets to it’s normal size and finally fades out.

You can see this effect in fruit ninja when player gets combo and how that “combo” text does all the things I just described.

3- How can I increase size of an object over time? For example I want to increase size of a display object for 2 seconds, so in every frame it’s size would get increased only by a small percentage.

4- And can we do bitmap fonts in Corona? [import]uid: 206803 topic_id: 35718 reply_id: 335718[/import]

add an enterframe listener to your runtime. then you have a function that runs on every frame where you can adjust things like the score etc. maybe you only want score to increment every 5th frame … you’d do something like this

frameCounter=0 onEnterFrame=function() frameCounter=frameCounter+1 if (frameCounter % 5 ==0 ) then if (currentScore \< targetScore) currentScore=currentScore+1 currentScore\_txt:setText(currentScore) end end end [import]uid: 32462 topic_id: 35718 reply_id: 142021[/import]

keep in mind to do that you have to have this line somewhere

Runtime:addEventListener( “enterFrame”, onEnterFrame )

and you will need to remove the event listener at the appropriate time. but that’s the general idea [import]uid: 32462 topic_id: 35718 reply_id: 142022[/import]

Thanks, I’ll try it ASAP.

What about my other questions? Any ideas anyone? [import]uid: 206803 topic_id: 35718 reply_id: 142029[/import]

local function removeIt(target)  
 display.remove(target)  
 target = nil  
end  
  
local function fadeOut(target)  
 transition.to(target, {time=500, alpha=0.0, onComplete=removeIt})  
end  
  
local function zoomIn(target)  
 transition.to(target, {time=500, xScale=1.0, yScale=1.0, onComplete=fadeOut})  
end  
  
local function zoomOut(target)  
 transition.to(target, {time=500, xScale=4.0, yScale=4.0, onComplete=zoomIn})  
end  
  
bonusScore = display.newImageRect("bonus.png", 128, 64)  
zoomOut(bonusScore)  

Or something like that. [import]uid: 199310 topic_id: 35718 reply_id: 142030[/import]

Grow then shrink any display object example - use chained transitions:

local function removeit()  
 display.remove(mytextobject)  
 mytextobject=nil  
end  
local function shrinkandfadeout()   
 transition.to(mytextobject,{xScale=1.0,yScale=1.0,time=500,alpha=0,onComplete=removeit})  
end  
-- Effect starts here, assumes text object is in mytextobject  
transition.to(mytextobject,{xScale=4.0,yScale=4.0,time=500,onComplete=shrinkandfadeout})  

There’s more compact ways to write this with lua closures, etc, but doing it this way is my preference. It makes tweaking the effects a little easier.
The answer to your third question is in the code above – use the transition.to function.
Good luck,
Scott
[import]uid: 31041 topic_id: 35718 reply_id: 142033[/import]

Pretty close to Rob’s eh?
[import]uid: 31041 topic_id: 35718 reply_id: 142035[/import]

I made a utility function that creates “drifting text” for scores that float up and fade out, etc. It’s similar to the effects you are wanting to do and may help you.

You can see the effect in this video:
http://youtu.be/w14s5FNZ-ek

…and you can find the tutorial here:
http://gamedevnation.com/game-development/drifting-text-a-utility-function/

Jay
[import]uid: 9440 topic_id: 35718 reply_id: 142044[/import]

Take a look at http://www.x-pressive.com/TextCandy_Corona/ they have some awesome stuff!

also support bitmap fonts [import]uid: 134049 topic_id: 35718 reply_id: 142070[/import]

add an enterframe listener to your runtime. then you have a function that runs on every frame where you can adjust things like the score etc. maybe you only want score to increment every 5th frame … you’d do something like this

frameCounter=0 onEnterFrame=function() frameCounter=frameCounter+1 if (frameCounter % 5 ==0 ) then if (currentScore \< targetScore) currentScore=currentScore+1 currentScore\_txt:setText(currentScore) end end end [import]uid: 32462 topic_id: 35718 reply_id: 142021[/import]

keep in mind to do that you have to have this line somewhere

Runtime:addEventListener( “enterFrame”, onEnterFrame )

and you will need to remove the event listener at the appropriate time. but that’s the general idea [import]uid: 32462 topic_id: 35718 reply_id: 142022[/import]

Thanks, I’ll try it ASAP.

What about my other questions? Any ideas anyone? [import]uid: 206803 topic_id: 35718 reply_id: 142029[/import]

local function removeIt(target)  
 display.remove(target)  
 target = nil  
end  
  
local function fadeOut(target)  
 transition.to(target, {time=500, alpha=0.0, onComplete=removeIt})  
end  
  
local function zoomIn(target)  
 transition.to(target, {time=500, xScale=1.0, yScale=1.0, onComplete=fadeOut})  
end  
  
local function zoomOut(target)  
 transition.to(target, {time=500, xScale=4.0, yScale=4.0, onComplete=zoomIn})  
end  
  
bonusScore = display.newImageRect("bonus.png", 128, 64)  
zoomOut(bonusScore)  

Or something like that. [import]uid: 199310 topic_id: 35718 reply_id: 142030[/import]

Grow then shrink any display object example - use chained transitions:

local function removeit()  
 display.remove(mytextobject)  
 mytextobject=nil  
end  
local function shrinkandfadeout()   
 transition.to(mytextobject,{xScale=1.0,yScale=1.0,time=500,alpha=0,onComplete=removeit})  
end  
-- Effect starts here, assumes text object is in mytextobject  
transition.to(mytextobject,{xScale=4.0,yScale=4.0,time=500,onComplete=shrinkandfadeout})  

There’s more compact ways to write this with lua closures, etc, but doing it this way is my preference. It makes tweaking the effects a little easier.
The answer to your third question is in the code above – use the transition.to function.
Good luck,
Scott
[import]uid: 31041 topic_id: 35718 reply_id: 142033[/import]

Pretty close to Rob’s eh?
[import]uid: 31041 topic_id: 35718 reply_id: 142035[/import]

I made a utility function that creates “drifting text” for scores that float up and fade out, etc. It’s similar to the effects you are wanting to do and may help you.

You can see the effect in this video:
http://youtu.be/w14s5FNZ-ek

…and you can find the tutorial here:
http://gamedevnation.com/game-development/drifting-text-a-utility-function/

Jay
[import]uid: 9440 topic_id: 35718 reply_id: 142044[/import]

Take a look at http://www.x-pressive.com/TextCandy_Corona/ they have some awesome stuff!

also support bitmap fonts [import]uid: 134049 topic_id: 35718 reply_id: 142070[/import]

Thanks for the incremental score code and I could integrate it into my game with no problem but problem is, the rate that the score increases is slow, I would like to have the same effect but happen very fast.

Like in Fruit Ninja, when score increases it gets increamented very fast. I set my FPS of my app to 60, but it’s still very slow and lame. [import]uid: 206803 topic_id: 35718 reply_id: 144797[/import]

Change the increment-by value to something higher than one until you get effect you want. It’s math: 60fps, +1 per frame will result in an increase of 60 points per second. +2 per frame = 120 points per second, etc.
[import]uid: 31041 topic_id: 35718 reply_id: 144798[/import]

edited.

(Why can’t we delete our posts?!) [import]uid: 206803 topic_id: 35718 reply_id: 144803[/import]