Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Quick questions about Gideros&Lua - Page 8 — Gideros Forum

Quick questions about Gideros&Lua

1568101114

Comments

  • olegoleg Member
    why is the value not 1?


    image.png
    633 x 259 - 21K
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    Hard to tell without knowing the transform applied, but it should be 1 if you had passed xx,yy. What is the value of yy in your case ?

    Likes: oleg, SinisterSoft

    +1 -1 (+2 / -0 )Share on Facebook
  • olegoleg Member
    @hgy29 I realized the sprite was moving
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+2 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited July 2018
    Guys, I don't get why my particles are not shown after tap?
    update: I didn't add them to stage LOL :D
    myStars=Particles.new()
     
    local function spawnStar(event)
    	myStars:setPosition(event.x,event.y)
    	myStars:addParticles({{ x=event.x,y=event.y,size=5,color=0xc0392b,ttl=200,speedX=2,speedY=2,decay=1.04 }})
    end
    stage:addEventListener(Event.MOUSE_DOWN,spawnStar)
    > 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)
  • Apollo14Apollo14 Member
    edited July 2018
    Guys, how to make classic smooth jump, that depends on how long we are holding the button?
    I'm experimenting with enterframe, but my jump height is fixed.
    function hero:init()
    	self.isJumping=false
    	self.jumpSpeed=4
    	self.gravityPower=0.1
     
    	self:addEventListener(Event.ENTER_FRAME, function()
    		if self.isJumping then
    		self:setY(self:getY()-self.jumpSpeed)
    		self.jumpSpeed-=self.gravityPower
     
    		if self.jumpSpeed<=-4 then self.isJumping=false; self.jumpSpeed=4; self:setY(self.origY)
    		end
     
    		end
    	end)
    end
     
    function hero:jump()
    if self.isJumping==false then
    	self.isJumping=true
    	self.jumpSpeed=4
    	self.origY=self:getY()
    end
    end</pre>
    > 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)
  • olegoleg Member
    edited July 2018
    scales=0.9 --підібрати експериментально
     
    --TOUCHES_BEGIN 
    if not isJumping  then
      tm= os.timer()
    end
     
    --TOUCHES_END 
    if not isJumping  then
      tm=os.timer()-tm
      jumpSpeed=tm*scales
      isJumping=true
    end
     
    --ENTER_FRAME
    if isJumping then
       playerY += jumpSpeed 
       jumpspeed -= gravityPower 
    end
     
    --collision
    isJumping =nil

    Likes: Apollo14

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited July 2018
    probably something like..
    Hero = Core.class(Pixel)
     
    function Hero:init(color, alpha, width, height)
      self:setAnchorPoint(0.5, 1.0)
      self:setPosition(160, 32)
     
      self.position = {x = 160, y = 32}
      self.velocity = {x = 0, y = 0}
      self.gravity = {x = 0, y = 960}
     
      self.jumping = false
    end
     
    function Hero:jump() -- set hero jumping
      if not self.jumping then
        self.jumping = true
        local g = self.gravity
        g.y = -2000
      end
    end
     
    function Hero:fall() -- set hero falling
        local g = self.gravity
        g.y = 960
    end
     
    function Hero:ground() -- set hero grounded
      self.jumping = false
    end
     
    function Hero:update(dt)
      local p, v, g = self.position, self.velocity, self.gravity
      local gy = g.y
      local vy = v.y + gy * dt
      local y = p.y + vy * dt
      if y >= 480 - 32 then -- stop hero falling out of world
        y = 480 - 32
        vy = 0
        self:ground()
      elseif y <= 32 then -- stop hero jumping out of world
        y = 32
        vy = 0
      end
      v.y = vy
      p.y= y
      self:setY(y)
    end
     
    local hero = Hero.new(0x44aa88, 1, 32, 32)
     
    -- update every frame
    local function onEnterFrameFunc(e)
      local dt = e.deltaTime
      hero:update(dt)
    end
     
    local function onTouchBegin(e)
      e:stopPropagation()
      hero:jump()
    end
     
    -- set hero falling
    local function onTouchEnd(e)
      e:stopPropagation()
      hero:fall()
    end
     
    stage:addEventListener(Event.TOUCHES_BEGIN, onTouchBegin)
    stage:addEventListener(Event.TOUCHES_END, onTouchEnd)
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrameFunc)
     
    stage:addChild(hero)
    That should work :)

    Likes: Apollo14

    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited July 2018
    Very odd.. when I look at my reply my code is truncated and I cannot see it in its entirety :(

    Do others see the entire code above or is it truncated at 'elseif y'??

    Here it is in plain text..

    Hero = Core.class(Pixel)

    function Hero:init(color, alpha, width, height)
    self:setAnchorPoint(0.5, 1.0)
    self:setPosition(160, 32)

    self.position = {x = 160, y = 32}
    self.velocity = {x = 0, y = 0}
    self.gravity = {x = 0, y = 960}

    self.jumping = false
    end

    function Hero:jump() -- set hero jumping
    if not self.jumping then
    self.jumping = true
    local g = self.gravity
    g.y = -2000
    end
    end

    function Hero:fall() -- set hero falling
    local g = self.gravity
    g.y = 960
    end

    function Hero:ground()
    self.jumping = false
    end

    function Hero:update(dt)
    local p, v, g = self.position, self.velocity, self.gravity
    local gy = g.y
    local vy = v.y + gy * dt
    local y = p.y + vy * dt
    if y >= 480 - 32 then -- stop hero falling out of world
    y = 480 - 32
    vy = 0
    self:ground()
    elseif y <= 32 then -- stop hero jumping out of world
    y = 32
    vy = 0
    end
    v.y = vy
    p.y= y
    self:setY(y)
    end

    local hero = Hero.new(0x44aa88, 1, 32, 32)

    -- update every frame
    local function onEnterFrameFunc(e)
    local dt = e.deltaTime
    hero:update(dt)
    end

    local function onTouchBegin(e)
    e:stopPropagation()
    hero:jump()
    end

    -- set hero falling
    local function onTouchEnd(e)
    e:stopPropagation()
    hero:fall()
    end

    stage:addEventListener(Event.TOUCHES_BEGIN, onTouchBegin)
    stage:addEventListener(Event.TOUCHES_END, onTouchEnd)
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrameFunc)

    stage:addChild(hero)

    Likes: Apollo14

    +1 -1 (+1 / -0 )Share on Facebook
  • talistalis Guru
    edited July 2018
    @antix it is truncated at 'elseif y' .
    Edit:
    < pre lang="lua"> < /pre> is not working. It is making the code whole again but in yellow format without highligt.
    < code> tag is also seems to be the same not working as it should work.
  • talistalis Guru
    edited July 2018
    It is funny indeed because when i try to edit your comment i saw the whole code, but when i close and return again truncated. So it is obvious something wrong with < pre > command.
  • hgy29hgy29 Maintainer
    It happens when you have a > symbol in your code, it is seen as a closing tag
  • antixantix Member
    @hgy29 oh, that's pretty bad when you want to have a code block. code without less than heheh :D
  • olegoleg Member
    Eureka!! =)
    why did not I know about it before?
    minX,minY,maxX,maxY=application:getLogicalBounds()
    stage:setClip(minX, minY, maxX-minX, maxY-minY)
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • oleg said:

    Eureka!! =)
    why did not I know about it before?

    minX,minY,maxX,maxY=application:getLogicalBounds()
    stage:setClip(minX, minY, maxX-minX, maxY-minY)
    what does it do? :)
    > 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)
  • hgy29hgy29 Maintainer
    antix said:

    @hgy29 oh, that's pretty bad when you want to have a code block. code without less than heheh :D

    Agreed, I wasn’t aware of it until yesterday. I will fix that next week.

  • Apollo14Apollo14 Member
    edited July 2018
    Can somebody please share quick example how to use Bump.lua? (I didn't find any examples)
    local pix1,pix2=Pixel.new(0x34ace0,1,24,24),Pixel.new(0x218c74,1,24,24)
    stage:addChild(pix1); stage:addChild(pix2); pix2:setX(400)
     
    stage:addEventListener(Event.ENTER_FRAME, function()
    	pix1:setX(pix1:getX()+1); pix2:setX(pix2:getX()-1)
    end)
    Do we need Bump only for rectangle collision detection, there's nothing else?

    p. s. Why not just use function instead of Bump?
    function checkCol(sprite1,sprite2)
    	local x,y,w,h = sprite1:getBounds(stage)
    	local x2,y2,w2,h2 = sprite2:getBounds(stage)
    	return not ((y+h < y2) or (y > y2+h2) or (x > x2+w2) or (x+w < x2))
    end
    > 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)
  • olegoleg Member

    @Apollo14

    обрізає
    kjhkhk.PNG
    1041 x 345 - 172K

    Likes: SinisterSoft

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited July 2018
    @Apollo14.. https://github.com/kikito/bump.lua that's the original documentation

    If you have 10 collision rectangles in your game then just use whatever but if you start to get a lot of collision rectangles bump is what you should use because it's fast and efficient and provides some in built collision responses.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited July 2018
    antix said:

    @Apollo14.. https://github.com/kikito/bump.lua that's the original documentation

    I didn't understand their documentation.
    Can you pls share a quick code example for Gideros, from where to start?

    Likes: oleg

    > 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 (+1 / -0 )Share on Facebook
  • antixantix Member
    @Apollo, the documentation for bump is very good IMHO and not too hard to grasp :)

    Anyhoo.. There was an interesting thread a while ago and I mashed a load of collision related stuff into it..

    http://giderosmobile.com/forum/discussion/6353/collision-with-any-object/p1

    Likes: Apollo14

    +1 -1 (+1 / -0 )Share on Facebook
  • olegoleg Member
    @Apollo14
    --для платформера достатньо цього =)

    Creating a world
    local world = bump.newWorld

    Adding items to the world
    world:add(item, x,y,w,h)


    Moving an item in the world, with collision resolution
    local actualX, actualY, cols, len = world:move(item, goalX, goalY, )
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • Apollo14Apollo14 Member
    edited July 2018
    Why does this line cause an error? How to make it work? (I've added Bump to project's plugin list, I'm using latest Gideros version)
    local world=require("bump").newWorld() --causes error
    local world=bump.newWorld() --causes error too
    lvls/lvl1.lua:44: module 'bump' not found:
    no field package.preload['bump']
    no file '.\bump.lua'
    no file '.\bump\init.lua'
    no file '.\_LuaPlugins_\bump.lua'
    no file '.\_LuaPlugins_\bump\init.lua'
    no file 'C:\Program Files (x86)\Gideros\lua\bump.lua'
    no file 'C:\Program Files (x86)\Gideros\lua\bump\init.lua'
    no file 'C:\Program Files (x86)\Gideros\bump.lua'
    no file 'C:\Program Files (x86)\Gideros\bump\init.lua'
    no file '.\bump.dll'
    no file 'C:\Program Files (x86)\Gideros\bump.dll'
    no file 'C:\Program Files (x86)\Gideros\loadall.dll'
    stack traceback:
    lvls/lvl1.lua:44: in function 'init'
    [string "property.lua"]:52: in function '__new'
    [string "property.lua"]:59: in function 'new'
    classes/scenemanager.lua:274: in function 'changeScene'
    main.lua:13: in main chunk
    All these dll/lua files usually have to be added to the folder manually? Or it is a little bug in Gideros' installation package?
    > 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)
  • olegoleg Member
    а ти додав плагін bump в андроід плеєр?
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • oleg said:

    а ти додав плагін bump в андроід плеєр?

    I'm testing it on PC player.
    > 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)
  • olegoleg Member
    спробуй додати цей файл https://github.com/MultiPain/gideros-platformer/blob/master/bump.lua
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    If you want to use the native bump plugin, use require “cbump”
    +1 -1 (+3 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    I changed the syntax highlighting code, hopefully code/pre blocks are now correctly rendered.

    Likes: antix, Apollo14, totebo

    +1 -1 (+3 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited July 2018
    Guys I'm trying to export blank Gideros Player with all these plugins:
    image
    And I'm getting this error:
    image
    How to solve it?
    exportPluginsList.png
    485 x 562 - 20K
    exportError.png
    613 x 718 - 41K
    > 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)
  • SinisterSoftSinisterSoft Maintainer
    It looks like google have taken play services 12.0.1 offline. Try 11.0.0 ?

    Likes: Apollo14

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited July 2018

    It looks like google have taken play services 12.0.1 offline. Try 11.0.0 ?

    Thanks, now I've tried 11.0.4.
    But there is next error. Some files are missing in the project folder.
    image
    exportError2.png
    614 x 1024 - 66K
    > 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)
Sign In or Register to comment.