This all happen when I press the fire key Z
Sorry I can't provide more info than this, but I really don't know what else to say.
Here is the entire code:
local sound = Sound.new("MakoBeamNCSGiderosCompRemix(-32Db).wav") local channel = sound:play() application:setBackgroundColor(0x0) width = application:getContentWidth() local username = "" local textInputDialog = TextInputDialog.new("Player1", "Enter Name Player1", username, "Cancel", "Save") backgroundtexture = Texture.new("BGComp.png") backgroundtexture = Bitmap.new(backgroundtexture) stage:addChild(backgroundtexture) backgroundtexture:setAnchorPoint(0.5,0.5) backgroundtexture:setRotation(90) backgroundtexture:setPosition(239,160) backgroundtexture:setScaleX(1.75) backgroundtexture:setScaleY(1.75) local retrofont = TTFont.new("8-BIT WONDER.TTF", 20, true) local text = TextField.new(retrofont,username) text:setPosition(0, 20) stage:addChild(text) text:setTextColor(0xfffffff) text:setScale(1.0) text:setPosition(10,20) bullet = Texture.new("bullet.png") bullet = Bitmap.new(bullet) stage:addChild(bullet) bullet:setScale(0.3) bullet:setPosition(0,0) bullet:setRotation(-90) playership1 = Texture.new("ship.png") playership1 = Bitmap.new(playership1) stage:addChild(playership1) playership1:setAnchorPoint(0.5,0.5) playership1:setPosition(245,300) playership1:setScale(1.0) --playership1:setColorTransform(0.1,0.9,0.3) local function onComplete(e) --if e.buttonIndex then username = e.text text:setText(username) --end end textInputDialog:addEventListener(Event.COMPLETE, onComplete) textInputDialog:show() left = false right = false shipX=width/2 playerDir=0 bDir=0 by= 1 bullets = {} counter = 1 Pool = Core.class(Sprite) function Pool:init() self.pool = {} end function Pool:createObject() local b --if there is anything in pool take it if #self.pool > 0 then b = table.remove(self.pool) else b = Bitmap.new(Texture.new("bullet.png", true)) end stage:addChild(b) return b end function Pool:destroyObject(b) b:removeFromParent() table.insert(#self.pool, b) end function gameloop(e) shipX=shipX + (playerDir* 5) if shipX<20 then shipX = 20 elseif shipX>(width-20) then shipX = width - 20 end playership1:setX(shipX) by=by+(bDir*5) bullet:setY(by) end stage:addEventListener(Event.ENTER_FRAME,gameloop) stage:addEventListener(Event.KEY_DOWN,function(e) if e.keyCode==KeyCode.LEFT then left=true playerDir=-1 elseif e.keyCode==KeyCode.RIGHT then right=true playerDir=1 elseif e.keyCode==KeyCode.Z then print("fire") bx,by=playership1:getPosition() bullets[counter] = bullet.new() stage:addChild(bullets[counter]) bullets[counter]:setPosition(bx,by) bDir=-1 counter = counter+1 end end) stage:addEventListener(Event.KEY_UP,function(e) if e.keyCode==KeyCode.LEFT then left=false if right then playerDir=1 else playerDir=0 end elseif e.keyCode==KeyCode.RIGHT then right=false if left then playerDir=-1 else playerDir=0 end end end) |
Thank's for your time.
Comments
https://deluxepixel.com
bullets[counter] = bullet.new()
Right ?
Here is how to do it:
Remove the whitespace in below example.
< pre lang="lua">
here goes your code to highlight...
< /pre>
And for your question:
1-Are you sure the name of the file is bullet.png (in android capital letter matters do not forget)
2-Check the file format also can it be opened by image viewer.
At a first glance, there are some things I would change:
I can see the Pool class but I can't see it initialized:
I think it's better if you copy Pool class at the beginning of the file, to be sure you have it available when you create its instance.
You create a Pool instance with
I suppose you don't need to add bpool to stage, since it's just a "repository"
In Pool:createobject()
I didn't test anything, this may contain errors :-\"
is line 89
main.lua:68: unexpected symbol near '='
main.lua 68 = a = {{"one", "two"}, 3}
and is part of this:
< pre lang="lua">
a = {{"one", "two"}, 3}
b = {k = a[1]}
< /pre>
Again... Very confused I've done exactly as directed by Talis.
Thank's for your support
If your error was in #89, and it was "TextureBase or TextureRegion expected, got no value" there is something wrong with some "texture object" you're calling in gameloop.
I think it's where you setX on playership1.
so I noticed one thing you're messing up: naming
You say it is a texture first, then you say that the same object is a Bitmap. This could be a good reason to have that texture related error.
try with
< pre lang="lua">
a = {{"one", "two"}, 3}
b = {k = a[1]}
< /pre>
[string "property.lua"]:39: bad argument #2 to 'setmetatable' (nil or table expected)
stack traceback:
[string "property.lua"]:39: in function 'class'
main.lua:65: in main chunk
So I'm going to make a new discussion on that because my question on this discussion has been answered.
Once again, Thank you for your continuing help and support.
So now were back to my first problem... It's giving me an error when I press the fire key Z.
But do not fear it's a different one so we're definitely getting there.
The Error is:
Fragmenter - animated loop machine and IKONOMIKON - the memory game
So as a result do not add this code that i posted no where in your main.lu please . It was just an example.
Note: I edited my post and deleted the code sample