Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Noobish questions :D
Started by H4ch1 Aug 30 2010 06:09 PM

- - - - -
5 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

H4ch1

[GLOBAL: userInfoPane.html]
H4ch1
  • Enthusiast

  • 74 posts
  • Corona SDK

Hi there,
I'm new to Corona, and apart from a little C, I'm new to coding :°
I got the hang of this, but I'm still a little unsure.
How do you save?
I mean, if I want to make a game where you can unlock levels as you play through the game, how can I save the results of the player when he quits the app?
I thought about writing the values in a txt, but even though I looked in the doc, I'm not sure at how I can, for example, find the "levels unlocked" words in my doc, and replace the number near it, or read that value and changing a value with that number.
Or is there another way to save?

Then again, if I create some objects within a loop, all those objects will end up with the same "name".
How can I track if one of those object isn't on the screen?
I thought about having an object with isSensor=true, and using the collision, event.other thing to remove event.other.
Is there a better way?

uid: 8486 topic_id: 1828 reply_id: 301828


[TOPIC: post.html]
#2

tetu

[GLOBAL: userInfoPane.html]
tetu
  • Contributor

  • 166 posts
  • Corona SDK

Hi H4ch1,

You might find useful this post by Gilbert for saving data: http://developer.anscamobile.com/code/save-and-restore-state

Suppose that we create 10 fruits with the loop:
for k=1,10 do
	 local fruit=display.newImage("fruit.png",0,0)
end
fruit is a variable name and not the object's name. using the same variable (fruit) we created 10 objects that do not have a name. if you have to give each fruit a name, you can assign a "name" property (or any other) to it
for k=1,10 do
	 local fruit=display.newImage("fruit.png",0,0)
         fruit.name="fruit"..k
end

i find it very convenient to store the fruits in an array
local fruits={}
for k=1,10 do
	 local fruit=display.newImage("fruit.png",0,0)
         fruits[#fruits+1]=fruit
end
from now on, whenever i want to refer to the 7th fruit, i use fruits[7]

an object isn't on the screen (assuming its rotation is zero) if
object.x-object.width/2<=0 or object.x+object.width/2>=display.stageWidth or object.y-object.height/2<=0 or object.y+object.height/2>=display.stageHeight
uid: 6459 topic_id: 1828 reply_id: 5462


[TOPIC: post.html]
#3

H4ch1

[GLOBAL: userInfoPane.html]
H4ch1
  • Enthusiast

  • 74 posts
  • Corona SDK

Thanks a lot tetu!
I'm looking in that save sample.
About the objects offscreen, I already knew what you said, my concern was more about how can I keep track of each one of them.
I mean, should I use an enterFrame listener? Calling a function with for loop that check if anyone of the object in my array is offscreen?
Wouldn't this be heavy for performance?
uid: 8486 topic_id: 1828 reply_id: 5469


[TOPIC: post.html]
#4

tetu

[GLOBAL: userInfoPane.html]
tetu
  • Contributor

  • 166 posts
  • Corona SDK

you are welcome!

you can store thousands of values in the text file (not just the level), and retrieve them when the application starts

it depends on how many and what kind of objects you want to track
an enterFrame listener is not a bad idea if you have few objects, but if you have hundreds of them timer.performWithDelay might be more efficient

check the performance on the device not the simulator
uid: 6459 topic_id: 1828 reply_id: 5480


[TOPIC: post.html]
#5

H4ch1

[GLOBAL: userInfoPane.html]
H4ch1
  • Enthusiast

  • 74 posts
  • Corona SDK

Thanks tetu! I'll try :D
uid: 8486 topic_id: 1828 reply_id: 5527


[TOPIC: post.html]
#6

H4ch1

[GLOBAL: userInfoPane.html]
H4ch1
  • Enthusiast

  • 74 posts
  • Corona SDK

I've encountered another problem.
From the documentation, it says that a param of transition is onComplete, that activates when the transition is over.
I wanted a function to be called after the transition, but it seems that it's called right when the transition start.

This is the little code:
for i=1, scene1.numChildren, 1 do
transition.to (scene1[i], {500, alpha=0})
end
transition.to (bg[1], {500, alpha=0, onComplete=loadNew()})
end

and then the loadNew() function change the alpha of another group from 0 to 1.
If I don't set a delay in the other transition (the one stored in loadNew), the fadein/out happens at the same time, and not when the first transition is complete.
Everybody knows why?

EDIT: Solved. Seems that with onComplete, when calling a function, I must not pass a target, or else it would fire immediately. So writing onComplete=loadNew solved everythings :D
uid: 8486 topic_id: 1828 reply_id: 5549



[topic_controls]
[/topic_controls]