Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Changing an images, using scene manager. — Gideros Forum

Changing an images, using scene manager.

i_Wattsi_Watts Member
edited January 2015 in General questions
require "box2d"
ice = Core.class(Sprite)
 
function ice:init(world, x, y, scale, xScale, yScale, strength)
	local ice = Bitmap.new(Texture.new("images/ice.png"))
 
 
 
	ice:setScale(scale) --
	ice:setScaleX(xScale)
	ice:setScaleY(yScale)
	ice:setAnchorPoint(0.5,0.5)
	self:addChild(ice)
 
	--create box2d physical object
	local body = world:createBody{type = b2.DYNAMIC_BODY}
	body:setPosition(x, y)
 
 
	body:setAngle(ice:getRotation() * math.pi/180)
	local poly = b2.PolygonShape.new()
	poly:setAsBox(ice:getWidth()/2, ice:getHeight()/2)
	body:createFixture{shape = poly, density = 0.5, 
	friction = 0.01, restitution = 0.3}
 
	self.body = body
	self.body.type = "ice"
	self.body.strength = strength
 
	ice.body.bitmap = ice -- 
	self.strength = 100   -- 
 
 
end
and in my level 1 lua, in an on begin contact function I have this
	if bodyA.strength == 90 then 
	print("crack image")
 
	-- Replace image with "cracked" version of image
	bodyA.bitmap:setTexture(Texture.new("images/crackedice.png", true))
 
	elseif bodyA.strength == 80 then 
	bodyA.bitmap:setTexture(Texture.new("images/crackedice2.png", true))
 
	elseif bodyA.strength == 70 then 
	bodyA.bitmap:setTexture(Texture.new("images/crackedice3.png", true))
 
	end
However, when I hit the ice, the image does not change. This logic worked, however once I implemented scene manager it stopped working. Any ideas?
Thanks.




Comments

  • piepie Member
    @i_Watts I don't know every bit of your code, but:

    if bodyA is an instance of ice I'd say it won't "break" since its strenght is 100, and this value it's not included in your if ..then statements.
    :)
  • talistalis Guru
    edited January 2015
    if you try to directly change like this is it changing?
    ice:setTexture(Texture.new("images/crackedice.png", true))
    Just one more issue maybe it is nothing related but first you define ice as a global variable, than you define inside your function as local? can you change this part like:
    -- local ice = Bitmap.new(Texture.new("images/ice.png")) --change this part as below 
    ice = Bitmap.new(Texture.new("images/ice.png"))
    Just guessing :D

    Note: And you can highlight your code in forum as below, just fyi :D

    <pre lang="lua">
    Your code here
    </pre>


  • no dice. the image still doesn't want to change. It doesn't like the bodyA part. or the body part.
Sign In or Register to comment.