Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Kill level? - Page 2 — Gideros Forum

Kill level?

2»

Comments

  • jdbcjdbc Member
    edited April 2018
    Paulo777 said:

    jdbc said:

    Why are you using this code?

    self:removeEventListener(Event.ENTER_FRAME, self.onDetectCollision, self)
    ANSWER: It is an EnterFrame event to detect if a gear shot collided with ship.

    You are removing a wrong EventListener, it should be just
    self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame)
    and this?
    stage:removeEventListener(Event.ENTER_FRAME, self.shot.onFire, self.shot)
    why are you using stage instead of self (current scene)
    ANSWER: I had trouble using 'self', maybe something simple to solve but as it was working I left it this way.

    You have to stop music and removelisteners before change scene (reset same scene),
    for instance:
    self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame,self)
    self:removeEventListener(Event.TOUCHES_BEGIN, self.onPaddleTouches, self)
    self:removeEventListener(Event.TOUCHES_MOVE, self.onPaddleTouches, self)
    self:removeEventListener(Event.TOUCHES_END, self.onPaddleTouchesEnd, self)
    removes onEnterFrame listener, and touch listeners.
    This when? Level? Ship? Gear? all? Is this functions to add?


    You have to call removeEventListener before change scene (Level) always. There should be addEventListener previous. But you are removing a listener that does not exist in your code.

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
  • jdbcjdbc Member
    edited April 2018
    I have restarted the same scene (using sceneManager) one and one in most of my games and works ok.

    Gideros is not the problem, if you remove objects they are removed, if you remove listeners they are removed.

    You should look to my Dots source code and try to use Core.class() in a better way than you are using to avoid most of your current problems.

    Do not use functions inside classes functions for instance, and use classes functions for drawing and gameplay.

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
  • jdbcjdbc Member
    edited April 2018 Accepted Answer
    I found your mistake: you are using global gear variable. Just use self.gear
    self.gear = Gear.new(ship)
    if you use gear as global variable the sceneManager.changeScene() does not remove gear of course.

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
  • jdbc said:

    I found your mistake: you are using global gear variable. Just use self.gear

    self.gear = Gear.new(ship)
    if you use gear as global variable the sceneManager.changeScene() does not remove gear of course.
    I tried using both ones... and both ones gets the same result
  • jdbcjdbc Member
    Accepted Answer
    For me it is working... I have restarted scene after dying and self.gear is removed.

    You could try self.removeChild(self.gear) also before changescene

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
  • jdbc said:

    For me it is working... I have restarted scene after dying and self.gear is removed.

    You could try self.removeChild(self.gear) also before changescene

    But I should declare it inside 'init' right?
  • Paulo777Paulo777 Member
    edited April 2018
    @jdbc I tried it over again and was EXACTLY that! I was not declaring it inside init. Now It works like a charm!! Living and learning hahah! Really thank you for the help and time spent!! Now I can remove their event listeners and kill them completely!!

    Likes: jdbc

    +1 -1 (+1 / -0 )Share on Facebook
  • Now I get the question: Why is it working with 'self' and not with 'local' ?
  • piepie Member
    Locals as the name suggests are local things: they are faster to access than any other variable or property, but they have a downside which is they are available only in their scope (their "function").
    Self instead refers to a property of a class, (which is a variable too in the end) which is bound to the class itself, and therefore it's available throughout the whole class (ie in any method of the class - methods are functions of a class- or from outside of it, as long as the class instance is accessible)
    Have you read Programming in gideros by arturs? It's a bit outdated but totally valuable to understand the basics of gideros. Last time I saw it online its price was less than 10$ as digital dl :)

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
  • Paulo777Paulo777 Member
    edited April 2018
    @pie I will try to get it... Aways see its sayings when I was trying to learn something. Now It is working as expected but I had to make these changes:
    --init function
    self.gear = {}
    self.nogears = 0
    and in every given time (counter == 100) etc
    self.nogear+=1
    self.gear[self.nogear] = Gear.new(ship)
    self:addChild(self.gear[self.nogear])
    and in a given time, for example in my case:
    if self.counter == 1100 then
    --add the last one
      self.nogears += 1
      self.gear[self.nogears] = Gear.new(ship)
      self:addChild(self.gear[self.nogears])
      self.counter = 0 -- now it will repeat and keep adding gears to the table
    end
    In the function of restart I use that method of killing sprites @antix posted, and now it is working like a charm!

    Thanks @jdbc @antix for the support
    Thanks everyone! :smiley: :smiley: :smiley:
  • piepie Member
    Instead of keeping track of self.nogear you can use the length operator #
    self.gear[#self.gear+1] = Gear.new(ship)

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    @Paulo777 dude.. my code works, you just aren't using it correctly :D

    Just looking at your code now.. a SHMUP.. nice.. one of the example games in my book (I hope to complete it one day) will be the same genre ;)


    Likes: Apollo14, Paulo777

    +1 -1 (+2 / -0 )Share on Facebook
  • antixantix Member
    edited April 2018
    @Paulo777 the main problem you have is that your code is very messy and inefficient. It mostly works but it doesn't work 100% For what you have you are doing really well for a beginner.. don't give up!

    I could rewrite the entire thing for you but really it would take me days and whilst I would enjoy the challenge, I just don't have time for that. So in lieu of a total rewrite I've made an example project this evening that demonstrates one way to add gears and bullets, check collision between them, and remove them on collision.

    The game scene should serve as an example of a good (IMHO) scene containing all the required functions to manage transitions.

    You will see in the example we start the game scene. From there it creates two sprites (gears and playerProjectiles) and attaches them to its self. These two sprites (or groups) are where we will attach our gears, and yes.. playerProjectiles. This makes things really easy to process because we just iterate (backwards) through each groups children, processing and disposing them as required.

    A number of gears are spawned when the scene starts and a new gear is spawned every couple of seconds. The gears move downwards and are disposed of when they leave the bottom of the screen.

    Touching the screen will spawn a playerProjectile which travels up the screen and is disposed when it leaves the top of the screen.

    During it's update, each playerProjectile checks if it has collided with a gear and if so, both objects are disposed.

    The collision method used is point in rectangle but the code is present (commented) if you want to switch back to rect in rect.

    There are TextFields to show how many of each object there are currently on screen.

    Something to note is that unlike your code, the gear and fire classes are subclasses of the Bitmap class. This is more efficient and as long as you supply the texture parameter first you can supply others as well.

    If you have questions ask, right now I'm going to bed :D
    zip
    zip
    Projectiles.zip
    13K

    Likes: Apollo14, Paulo777

    +1 -1 (+2 / -0 )Share on Facebook
  • Paulo777Paulo777 Member
    edited April 2018
    Omg @antix thanks again for the tips and support. I'm a begginer on Gideros and Lua and this project is at a glance for learning and understanding how Gideros works and to learn a new programming language to me that is Lua, coincidently created by Brazillians haha! On this project I was really doing tests and if it works, I'd leave it so... But I'm on the road to construct a code and logic that is efficient and with best practices, using the maximum Gideros can offer... :blush: I have toooo much to learn and that is what I want to do.

    I looked at your code! I feel amazed! There is to much to learning with that! One of the things I've figured out, you use I mean, custom events
    self:removeEventListener("enterBegin", self.onTransitionInBegin, self)
    and that sometimes you use 'stage' to add sprites and sometimes not. I'd like to know differences

    Also this is a thing that I didn't know
    GAME = self
    You used
    math.randomseed(os.timer()) for i = 1, 4 do math.random() end -- shake it up
    I never knew about it
  • antixantix Member
    @Paulo777 you are welcome. It took me a little while to get used to how everything works but eventually it will fall into place ;)

    Custom events are very cool but as with any event, use them sparingly. The only custom events I use personally are the ones required for correct operation of SceneManager.

    Making a variable (in the case of the example the game scene) global means that you can then access that scene from any other scene. It is very handy, though some might say a bit lazy ;)

    Setting the random seed and then throwing a bunch of random numbers at the beginning of your code is a good way to actually get random numbers.

    Adding sprites to other sprites is very useful for grouping sprites. So if you make one sprite and then attach 50 children sprites to it, when you move the original sprite, all of the others will seem to move at the same time. So add your groups to the stage (or the scene where they are being used) and then add children to the group.

    I hope that clears a few things up for you. And btw, your code is probably a little tidier than my original spaghetti ;)

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
  • @antix surely It does! Now I got a better vision of how things works.

    @jdbc , looking at your code, I've noticed that there is a file with setting for multi-language. As an android programmer into an android prepared development enviroment, I have folders with the specific language and inside of it I have xml files with "strings" inside of it. But in Gideros this is a little different. Can you or anybody else if knows, light it for me on how it works in Gideros?
  • Apollo14Apollo14 Member
    edited April 2018
    @Paulo777 personally for multi-languages I've decided to simply do it with tables. More advanced practices can be adopted later on.
    mainArr= {"Hi dude!","How are you?","How is mom?"}
    esES = {"Hola amigo!","Cómo estás?","Cómo está mamá?"}
     
    if application:getLocale() == 'es_ES' then
    	mainArr = esES
    elseif application:getLocale() == 'tr_TR' then
    	mainArr = trTR
    elseif application:getLocale() == 'ru_RU' then
    	mainArr = ruRU
    --etc...
    end
     
    txt1 = TextField.new(segoe, myArr[1])
    --etc...
    Recent discussion with more advanced solution: http://giderosmobile.com/forum/discussion/comment/55265/#Comment_55265

    Likes: antix, Paulo777

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+2 / -0 )Share on Facebook
  • jdbcjdbc Member
    Paulo777 said:

    @antix surely It does! Now I got a better vision of how things works.

    @jdbc , looking at your code, I've noticed that there is a file with setting for multi-language. As an android programmer into an android prepared development enviroment, I have folders with the specific language and inside of it I have xml files with "strings" inside of it. But in Gideros this is a little different. Can you or anybody else if knows, light it for me on how it works in Gideros?

    This my solution for multi-language. Just define a file with languages and key/value with translation and getString(key) function. Quite easy.

    Likes: Paulo777

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.